#Rotation when on a slope

21 messages · Page 1 of 1 (latest)

inland gorge
#

For the past 4 years ive tried to figure out how to make characters rotaions match the angle of the slope they are on. Like sonic for example. I seriously need help please!

inland gorge
#

Let this COOK

sweet bronze
#

Rotate it to match the normal vector of the ground

inland gorge
tender galleon
# inland gorge Let this COOK

you can fetch the normal of the ground very easily, the normal is the direction away from the surface - so simply get the angle of that, and you know the angle of the surface, and you can rotate your character based on that. you might need to adjust it by 90 degrees, though, since I think 0 rotation is to the right and not up?
check CharacterBody2D for "normal," there are multiple ways to fetch it iirc!

serene wadiBOT
#

Online API Reference for CharacterBody2D. You can also use the offline documentation by pressing F1 in Godot and searching for a class name.

tender galleon
#

in your case you probably want to get the last collision and get the normal from that, unless you're adjusting the direction it considers down for purposes of "am I on the floor?"

#

since getting the floor normal only works when, yknow, on the floor

inland gorge
#

Just know you are a goat bro

#

An honest goat

quick harness
#

Simple

#

Managed to do it?

worldly thicket
# inland gorge For the past 4 years ive tried to figure out how to make characters rotaions mat...

Okay this is sometimes a little inconsistent at times but it seemed to work for me. https://gist.github.com/sockeye-d/0bf32dd8e54a8e7f45c85130aa7fcd39
Basically what it does is it gets the floor angle, and computes the proper rotation and up direction for the CharacterBody2D. All the "raw" velocities from things like gravity and movement inputs are transformed according to body's current rotation. Any collider seems to work pretty well, but circles and rounded boxes work especially well.

Gist

A simple player controller for Godot. For #1248051984779579403 message - rotating_player.gd

worldly thicket
#

I changed the script to use a downward-facing raycast instead of relying solely on the collision information

echo bay
#

Maybe do a collision on the lowest point in the circle when the player enters. Take the exact height from the loop and place an anchorpoint at the center of it. Rotate the player using that anchorpoint and when the player is down again simply move forward again.

inland gorge
#

Honestly

#

You all are the best man