- Home /
Question by
knuckles209cp · May 02, 2019 at 10:42 AM ·
rotationjavascriptquaternionsmoothnormalized
Lerp with raycast hit.normal?
When my player is in the air or on the ground, I'd like the player to follow the normals of the floor but smoothly, At the moment it is snapping to the normals and I cant seem to figure out how to implement hit.normal with Quaternion.Lerp.
var AirHit : RaycastHit;
if (Physics.Raycast(transform.position, Vector3.down, AirHit)) {
SnowMesh.transform.rotation = Quaternion.Lerp(transform.rotation, AirHit.normal, 10 * Time.deltaTime);
}
var airheight = AirHit.distance;
playerHeight = AirHit.distance;
}
Comment
Answer by myzzie · May 02, 2019 at 12:04 PM
Lerp form current rotation to target rotation
It doesnt want to work with hit.normal, I have tried a few things but cant seem to do anything with it without errors. hit.normal is a must.
transform.rotation = Quaternion.Lerp(transform.up, hit.normal, Time.time * 5);
Answer by BigoG · Sep 15, 2020 at 06:28 AM
Someone might need this, here you go
transform.up = Vector3.Lerp(transform.up, hit.normal, Time.deltaTime * 10);