Skateboard gliding mechanic help

Godot Version


I have created the following script so when the player hits a rail, it glides along it like a skateboarder. What I need help with is how I can convert this so that it prevent’s the player from moving vertically if the rail was angled. I’ve tried various different variations of doing a seperate detector for angled rails, to changing this script to factor in rail’s that are angled, but so far I am having a bit of trouble as none have worked. All feedback is appreciated thanks :slight_smile: .

func handle_grinding(_delta):
velocity.y == 0
# If player is not moving horizontally when grinding starts, give some initial speed
if abs(velocity.x) == 0:
velocity.x = grind_velocity
# Maintain constant speed along the rail
velocity.x = grind_velocity * sign(velocity.x)“Grind”)

# Move along the rail smoothly

# Check if the player is no longer on the rail
if not rail_detector.is_colliding:
	is_grinding = false

what does this line do?
should it be velocity.y = 0

I’ve just removed it and the function still works as it was before. I changed it to that from velocity = 0 because having that makes the player bounce out of the rail’s collision.

can you create a clip or some image to illustrate your problem