- Home /
Question by
valriecorinne · Jul 24, 2018 at 05:15 AM ·
rotation2d-platformerslope
How should I rotate my character on a slope? (2d game)
Currently when my horizontal ray hits a slope, the code immediately sets the character's rotation to equal the slope:
float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
transform.rotation = Quaternion.Euler(Vector3.forward * slopeAngle);
This works but when the character rotates, it turns so it's hovering above the slope. I'm thinking of rotating it when the last vertical ray hits the slope instead, but I'm not sure if that's the best solution. I've tried playing around with lerp but it doesn't seem to work. Any suggestions would be helpful, thanks!
Comment
Is it needed for you to manage character movement that precisely? You could use a rigidbody so your character can go up a slope and simply manage the velocity and rotation.