2D Rotation jitter when going up slopes

Godot Version

v4.2.2.stable.official [15073afe3]

Question

Does anyone have any idea on how to fix this rotation bug. It keeps resetting 0 then back to it’s original value erratically when going up slopes

this is what I’m using for the rotations:

rotation_degrees = -rad_to_deg(ground_angle())

func ground_angle():
return get_floor_normal().angle_to(Vector2(0, -1))

If you print out rotation_degrees is it jumping around?

Also are you just assigning that to the players rotation? If so then you shouldn’t be converting it to degrees.

1 Like

it does jump around, in the video it shows it going to 0 then back to normal

and also it doesn’t rotate without converting it to degrees

Ah yeah I see that now. Are you rotating just the image? Going by the documentation get_floor_normal only returns when is_on_floor is true, so if you’re rotating the collision box maybe it’s nolonger on floor and thats causing the jumping. Huh that’s strange, as far as I’m aware all rotations were in radians…

I think it does have to do with it no longer being on floor. I used the console and it showed it not being on floor whenever rotation would reset

You can turn on visible collision shapes in the “debug” menu in the top left.


If you want to simplify you math you could do this, angle_to the UP vector is the same as +PI/4, and best to keep the values in radians instead of degrees.

rotation = get_floor_normal().angle() + PI/4

You may want to look into floor snapping and apply_floor_snap(). I’ve not used it, but I believe that’d fix the no longer on floor issue.

2 Likes

This one worked for me. I just needed raycast to detect the floor to allow jumps. Thanks a lot!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.