Rotating the player based on the terrain below them

I want to make the player’s character to rotate so their feet are always flat on the terrain’s surface in case the player runs up a hill.

I also would like to know if there’s a way to make a player hang off a ledge, like this:


Are there any mechanic tricks for this?

2 Likes

For feet planting, use Inverse Kinematics (IK) to determine what angle you need the hips/knees/feet to be at to put the feet aligned with the surface normal.

Here’s some resources for IK pertaining to Roblox to get started:
http://wiki.roblox.com/index.php?title=Inverse_kinematics
https://www.youtube.com/watch?v=UNoX65PRehA
https://www.roblox.com/games/167637083/Inverse-Kinematic-Characters-Open-Source

For ledge grabbing, you can also use IK to position the arms perhaps.

For detecting the ledge itself, this is a lot trickier and there’s not one best solution for this. If you are confident enough with math, you could try to write code that calculates where the ledge is for several primitive shapes (box, wedge, pyramid, …). You won’t be able to calculate ledges for CSG/meshes since you can’t read vertex data.

Another solution may be to use extra invisible parts placed on top of the world that you put over the ledges, and you just scan for these nearby parts.

7 Likes

I believe that inverse kinematics(IK) is what you are looking for. I am not sure if there are any simple tricks for implementing IK on top of existing Roblox characters.

EDIT: Looks like Thomas kicked my butt on getting the lowdown and info on the subject.

2 Likes

Should be possible. You can manipulate Motor6D’s Transform property to change the angles on the joints, and you can use Humanoid’s HipHeight property to vary the height of the character off the ground if needed.

I’ve never done this myself though, so I may be overlooking some implementation details.

5 Likes

Actually, you are right. I have done similar stuff myself to dynamically update the character to face the direction of the mouse by editing the joints C0 and C1 in a similar way.

2 Likes