Godot Version
4.2.1
Question
Should projectiles be of type RigidBody2D
or Area2D
? Does it even matter? And if it’s an Area2D
, can or should you move it using global_position
in _process()
or in _physics_process()
?
4.2.1
Should projectiles be of type RigidBody2D
or Area2D
? Does it even matter? And if it’s an Area2D
, can or should you move it using global_position
in _process()
or in _physics_process()
?
depends how you want it, rigidbody will need a bit more code to set it right, than just straight changing the position, but i believe with rigidbody2d the collider wont skip a wall if it went too quick example with bullet.
One other difference I’ve found is that Area2D
and StaticBody2D
seem to not be meant to collide… which makes somewhat sense if you think about it. If you disable monitorable
on an Area2D
, it won’t receive a body_entered
signal when a StaticBody2D
node enters its area – even though that’s the exact opposite of what monitorable
supposedly does, and more like what monitoring
does. Anyway, weird behavior.
But controlling the position of an Area2D
is much easier than applying forces to a RigidBody2D
, so for more tight control, I guess an Area2D
is a better choice.
Area2D is ok, I use too
Depends on how you want to move the projecticle and whether you want physics involved.
Examples:
Bullet in a space invaders style game that goes straight up the screen - Area2D
Missile arcing across the screen being affected by gravity. like in in say Worms - RigidBody2D
There are other types though as others have explained.
Areas can easily miss objects depending on velocity or physics step rate detecting nothing.
Areas are for overlap detection and not actual collision. Only bodies are for collision. For reliable projectile hit-detection never use areas, always use bodies.
The difference is, a “real” physics body detects small tunneling along its velocity path, does actual collision detection, and the physics engine will also correct the body when it is colliding with another body preventing it from going inside the other body.
For an Area if nothing overlaps at the moment the physic step updates it will detect nothing and no body can collide with an area. A body can only overlap the area at the time of the physics step.