Why a RigidBody2D object still moves even if it's not implemented inside the _process function?

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

I’m a Godot newbie, and I followed the tutorial (Dodge the Creeps) step by step, but I was curious of how the MobTimer’s timeout got the Mobs to move. On the contrary, I know why the Player moves, as it was implemented inside the _process function, but the Mobs weren’t. Why not implement Mobs’ movement inside the _process too? I guessed they rely with the timer while it ticks, but how do I multiply the delta time if they weren’t inside the _process?

:bust_in_silhouette: Reply From: p7f


how the MobTimer’s timeout got the Mobs to move

The MobTimer’s makes the mobs spawn and gives them a linear_velocity between max and min speed defined in mobs script. How does they move then? RigidBody2D is moved by physics engine, so if you set the linear_velocity physics engine will handle the movement with that velocity in the direction the mob is pointing to (which is set with mov.rotation in the main script). Have in mind that set_linear_velocity method is already inherited by RigidBody.

On the other hand, the player is not a RigidBody2D but an Area2D, so physics engine will not handle it’s movement. Thats why you must handle it yourself inside _process function (or _physics_process depending the situation).

Mobs movement has nothing to do with MobTimer’s tick or timeout. That timer only instantiate the mobs and sets them the required properties.

I finally got the idea after I’ve done some explorations on the engine. But anyway, thank you.

ryugomez | 2018-12-31 14:27

You are welcome. If you think this answer is correct, you may select it so other see the problem is solved. Or you could add your own answer if you think this is not enough. Either way try to select an answer so it’s easier for others with same question.

p7f | 2018-12-31 14:50

Thanks, I was trying to understand why the RigidBody node was used instead of an Area2D node for the mob. I get it now. My friend is trying to modify the tutorial so that you can hit the mob’s, but we weren’t sure how to get them to detect collisions.

bonsaipropaganda | 2023-04-28 04:04