Enemy Won't Spawn

I followed the code one for one and the enemy spawn fuction isn’t working. When I run the game, the enemy isn’t there. I have instaniated the EnemySpawner in the Game scene, so I’m not sure what went wrong. Any help is welcomed.

By this, do you mean you don’t see any enemies in the Remote Tab of the Scene Dock?

A few things to check:

  • Test-print statements throughout the control flow will print as expected in the Output (for example, I’d put one in spawn_enemy()). If any of them don’t print, that [function isn’t being called / condition isn’t returning true] when it should be.
  • Spawn timer set to Autostart, or you have a start() call in there somewhere
  • Enemy instances appearing in the Remote Tab of the Scene Dock
  • Enemies are actually moving as expected (I encountered the same problem you did, and it turned out that they were spawning in, but not moving)

It might even be worth temporarily moving the spawn positions onscreen so you can see them right away, just because they’re just as easily moved back once you have it working.

Thank you for replying, turns out when I moved the spawn positions on screen the Enemies were spawning, but not moving. If theres a way I can make the Enemies move as expected, please let me know.

1 Like

I didn’t want to mention too much at first, but as it turns out, I had exactly the same problem when I did this part. Here’s a breakdown of what was involved:

  • I think everything Kaan does up to this point is with weakly-typed GDScript, so variables can hold any type of value you give them.
  • Velocity was set to a whole number, for example 5. This is interpreted as an integer because it’s not 5.0, even though I had it in my head that velocity was going to be a float.
  • When a weakly-typed variable that currently has an integer value is set to some_integer * some_float, the result is rounded to an integer. Maybe there are other combinations of things that result in something else, but that’s what happened in my specific case (I haven’t looked into it too deeply).
  • Velocity was multiplied by delta, which is a float with a value close to 0.

You can probably see where this is going. Or, maybe more accurately, not going =)

Hopefully you had exactly the same issue I did so that this gets you back on track!

2 Likes

Found the solution to my problem The reason why the Enemies weren’t moving was because the script wasn’t attached to the Enemy Node. Definitely gonna check if my script is actually attached to it’s node next time.

1 Like

Sometimes it’s the simplest stuff that will catch us offguard. Nicely solved :+1:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms