Velocity overwriting each other?

Do not apologize for providing a thorough answer to my questions – it is highly appreciated. Your own thoughts on the subjects also help me understand the areas where you lack a bit of knowledge.


As a starting point I would like to address your actual issue. Unless I’m missing something, it seems that you have not utilized your State (base) correctly. State defines the function state_process() but in your ChaseState you’re using _process() in its stead. You’re not using the function provided by the base and this causes your entire system to function incorrectly as _process() is not accounted for in your CharacterStateMachine.

I believe that substituting _process() for state_process() in ChaseState will fix your issue.

There are two key things to remember about the concept of velocity. First is that it is a vector that describes an object’s change in position over time through a single variable: a vector. The vector representation is convenient because it implicitly contains two pieces of information: direction, and magnitude. The second thing to remember is that the SI unit used for velocity is metres per second (m/s). As such, velocity always describes an object’s change in position over 1 second.

In terms of how you should use velocity to change the player’s position, it is easiest to make use of move_and_slide(). This function will move your CharacterBody2D over time based on its velocity without the need to implement your own system for collision responses. You can read more about this on Godot Docs.

The only case where you should multiply with delta is when you need to move something over time. delta has a different value in _process() and _physics_process(), but it always describes the same thing: the time it took to perform a single update to the game.

If you’re interested in understanding this, and many other concepts, I recommend that you research how physics simulations manage to simulate the motion of objects. It’s highly relevant to game development as many game mechanics are essentially just contained real-time simulations.

I’m not sure how you interpret your own use of move_toward(). It’s just a utility function to make it easier to move towards a target value. On the other hand, changing the velocity is mandatory to move a CharacterBody2D with move_and_slide(). The way you change velocity is up to you.

Here’s the Godot Docs page on these functions. In a nutshell, _process() runs every frame and provides you with a delta that describes how long it took to process it – as a result, delta will vary. On the contrary, _physics_process() runs at a fixed rate. The reason for its fixed update rate has to do with physics stability and is why there are two process functions (or similar) in almost any game engine; one for physics, and one for generic stuff like game logic and what not.


Hopefully this fixes your issue and helped you grasp some of the concepts you’re actively using. Let me know if you have any further questions.

1 Like