Best node for a bullet?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DodoIta
:warning: Old Version Published before Godot 3 was released.

Hi again!
I need an advice on this: I wanna create a gun which shoots bullets in a top-down shooter, as simple as that, so I want the bullet to move and detect collisions.
I tried using a KinematicBody2d but I couldn’t move them at the same speed using the move() function, so I looked at other demos and I saw people using a RigidBody2D (platformer 2d demo).
So, the question is: which node is the best in this case and what are the differences (i.e. different options to move the sprite, etc.)?

There is no best at all, it depends on even more parameters about your bullet, and mostly the speed of it.
What do you mean by “I couldn’t move them at the same speed using the move() function”? Bullets move like characters, aren’t they?

Something about speed:

If your bullet has a moderate speed (slightly faster than a character), then a RigidBody could be fine.

If it is really fast (a few frames to hit the target), then maybe a RigidBody is still possible but you’ll hit a limitation most physics engines have, which is tunneling: the bullet will pass through the target because the distance travelled between two frames is higher than the size of the hitbox. CCD mode attempts to solve this but Godot doesn’t seem to support it well at the moment. Increasing the size of the bullet’s hitbox can help but leads to bias, so RigidBody can also be dropped and use a custom script relying on raycasts instead.

If it is instant (laser), then there is no speed to consider. It will just be a two-ended node coming from the gun to the first hitbox using a raycast.

I would say only the first case can make use of a RigidBody, but all of cases can also work using custom scripts and nodes as well. (I also know someone who used no nodes at all, so everything is possible :p)

Zylann | 2017-03-05 16:36

About the move function, it was my mistake.

Understood, thank you! :slight_smile:

DodoIta | 2017-03-05 22:49

:bust_in_silhouette: Reply From: eons

Design your arsenal and look all the ways you can make each shot according their properties (motion, reactions, duration).


For simple bullets I prefer monitored Area2D, bullets normally don’t need to react to hits but the target is the one that does stuff like getting hit by the bullet.


If bullets need to know when they hit something, kinematic bodies could be good, in particular if bullets takes physic space in the game (sometimes you may need move, sometimes set_pos, sometimes both…).


If you need some high speed bullets that are not an instant ray or bullets that bounce, are affected by gravity, move things according to mass and other physics stuff, rigid bodies may be better.


For non rigid bullets, if the bullets go on a barrage, forming patterns and things like that, a barrage manager could be added to move every bullet each frame instead of letting every bullet calculate their movement.


For instant shots (lasers, quick short range shotguns) a ray or an array of rays may be better, in some cases just a sprite that cast a ray or check a shape in a specific frame.

Quite thorough, thank you!

DodoIta | 2017-03-06 15:17

:bust_in_silhouette: Reply From: Warlaan

I can’t really side with the answers given so far. In my opinion the obvious choices are a RayCast (for bullets of infinite velocity) or a RigidBody.

Areas are currently buggy when they are moved. Apparently they were meant to be used for static areas (hence the name), so sometimes when an area moves into a collider (instead of the collider moving into the area) it doesn’t trigger.

KinematicBodies are moved in the gameplay code which runs on another thread than the physics code, so at the least you are moving workload to the (most likely busy) gameplay thread that could be performed on the physics thread. Apart from that RigidBodies already have functions to move with a constant velocity while you would have to rewrite that code in a KinematicBody (it’s just a couple of lines, but still).

For fast RigidBodies you do need to activate CCD which afaik works fine. In previous versions you had the choice between two types of CCD of which one was buggy, but that was disabled since.

Areas are currently buggy when they are moved. Apparently they were meant to be used for static areas (hence the name), so sometimes when an area moves into a collider (instead of the collider moving into the area) it doesn’t trigger.

Can you expand on this? What circumstances are “sometimes”? Are you talking about 2D or 3D? I haven’t seen this happen in practice - much like the accepted answer above, I tend to prefer Area2D for bullets and it’s been working well.

kidscancode | 2017-03-06 20:00