0 votes

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?

asked Dec 30, 2018 in Gossip by ryugomez (31 points)

1 Answer

+1 vote
Best answer


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.

answered Dec 30, 2018 by p7f (1,868 points)
selected Jan 3 by ryugomez

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

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.