- Home /
Smoothing orientation to surface normal rotation
Hi,
I am having difficulty working out how to smooth the rotation of my player character as he aligns to the surface normal of the sloping ground he is walking on. At present I'm using a raycast to align the player to the surface, and the way I have it set up he snaps to the orientation of the surface as it changes, which looks bad. I'd like it to ease into the new orientation over the course of about a second, instead of snapping immediately to it. I think it could be done with a Slerp, but I've so far failed to code it correctly. Could anyone offer me any help with this and show me how to get this working correctly?
Here is the code for the orientate to surface I have so far, which produces the orientation snapping result:
private var yRotationOffset : float = 0; function Update() { var hit : RaycastHit; var castPos =Vector3(transform.position.x,transform.position.y-.25,transform.position.z); if (Physics.Raycast (castPos, -transform.up, hit, 20)) { transform.up = hit.normal; transform.Rotate (0, yRotationOffset, 0);
Thanks for any help and advice on this (o: