In my platformer game, I want my character to rotate to the angle of the slope they are standing on. However, to make this work properly I dont want them to suddenly rotate to the angle upon making contact with the slope else it will look horrible and undoubtedly throw up a tonne of collision issues. Instead, I want them to gradually rotate as shown in the images, so that they will rotate as much as they can each frame until they cant any further due to a collision with the back corner. How would I do this, and how would I change the pivot point of the character to the front bottom corner in order to make this work? Code in C#. Thanks.

You don’t have to have visual and collision representations of the level be the same. What you can always do is a sharp corner in the visual representation and a smooth round (or at least a polygon with more steps to approximate roundness) collider int the collision representation.

Do you really need the precise placement shown in the pictures to the right? Most games let there be a little overlap – your feet are in the grass, or bushes, or soft dirt … . If you need that picture it seems like more of a trig problem (it won’t slowly rotate – it will snap to the computed math rotation as it moves, which will slowly change.)

But most games, when you hit the slope, will slowly spin, will put your back foot through the ground, but you’ve probably moved by then anyway. You can look up finding the normal and gradual rotations.

Hi ,

Use the script below -

`````` RaycastHit hit;
Quaternion rot;
public  int smooth;

void Update()
{
Ray ray = new Ray(transform.position, -transform.up);
if (Physics.Raycast(ray, out hit))
{
rot = Quaternion.FromToRotation(transform.up, hit.normal) * Quaternion.Euler(0, transform.rotation.y, transform.rotation.z);
transform.rotation = Quaternion.Lerp(transform.rotation, rot, Time.deltaTime * smooth);
}
}
``````