#Issues with floor snapping when moving in a specific direction

5 messages · Page 1 of 1 (latest)

iron acorn
#

I am working on a project with a player controller similar to the classic Sonic games or the Fancy Pants series.
I would like it to align itself with the floor it's standing on, and move relative to that floor. However, I have an issue where it fails to stay aligned to the floor when moving left, instead detaching and reattaching repeatedly. When moving right, it works (mostly) as expected.
I've attached a video of the issue and the player node's script.

#

Possibly also relevant

#

i'm probably missing something obvious tbh

iron acorn
#

i'm thinking it might be due to the way i'm using get_floor_normal()? but it's not obvious to me what's wrong about it

reef hollow
#

My guess is that the body is jumping around a little as you go up and down slopes, so is_on_floor_() is giving erratic results. You might be able to "debounce" it a little though:```py

class-level variable

var last_left_floor_ticks: int
last_left_floor_ticks += 1
if is_on_floor():
set_rotation(get_floor_normal().angle() + (PI/2))
up_direction = get_floor_normal()
floor_max_angle = rad_to_deg(45)
last_left_floor_ticks = 0
# 3 is adjustable (probably replace with a constant somewhere)
elif last_left_floor_ticks > 3:
set_rotation(0)
up_direction = Vector2.UP
floor_max_angle = rad_to_deg(80)