Bullets not evenly spaced

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Socrates

In my game, when the player fires a weapon that repeats, like a machine gun, the bullets are not evenly spaced. I’m not sure if this is because of the way I’m creating Vector2s on the fly which might be causing some stuttering or if it is some rounding error with the timer or if I’m just creating bullets in an incorrect way (some stuttering does seem to occur once a dozen or so bullets are on the screen). Here is the code for the weapon: Imgur: The magic of the Internet And here is an image of the problem: Imgur: The magic of the Internet

If I try declaring the velocity as a Vector2 in the bullet code I get errors when I try to set the x and y (it says I’m trying to access a “nil” variable with an int).

What kind of body is your bullet?

kidscancode | 2018-04-16 03:49

It’s a Node2D with a KinematicBody2D, but I’m not using the KinematicBody2D part for anything. It’s really just a Sprite with an Area2D.

Socrates | 2018-04-16 05:13

Why so many nodes? It sounds like all it needs is an Area2D, CollisionShape2D, and Sprite. What purpose does the Node2D even serve? Simplify your node structure and you’ll avoid a lot of unintended behavior.

One possibility: if you have a CollisionShape2D on the kinematic node, then you’re probably causing the physics engine to try and resolve collisions between the bullets.

kidscancode | 2018-04-16 05:24

The kinematic body is just there because i thought i would need that behavior (I need it for other projectile types) but it’s not doing anything. I just deleted it to make sure and the timing issue is still present. And I tend to make everything a Node2D so I can easily swap in and out any other nodes I might need.

Socrates | 2018-04-16 05:50