Hey guys!
My character just slides off the screen and I can’t figure out why.
Here’s my code from a tutorial for x-movement, which I tried to “hack” into a four-directional movement code. It is part of a state-machine where I call these functions in their respective states. Here’s (part of) the code:
No need to change your code to my example. You can calculate velocity in any place you like and pass result to you CharacterBody2D where you call move_and_slide(). Don’t forget that move_and_slide() should be in _physics_process (and probably your velocity calculations) since it handles collision with physical objects.
You are probably modifying it somewhere in the code.
Try debugging with print() at each step where you changing values. First - your final velocity, and if Y-axis actually bigger than desired, check the code where you calculating it by printing out those values, and so on, walk backwards trough your code/functions. Also, i am pretty sure, that you don’t need to use “delta” with move_and_slide() function, so it may cause some buggy behavior. You can also change your CharacterBody2D “Motion_Mode” to “Floating”, to be sure, that gravity is not a factor.