- Home /
How to rotate towards the mouse on one axis while snapping
Hi all, This one's been bugging me for a while now so thought I'd see if any of you fine peeps could help me with it.
I have a character who is lerping towards the mouse:
transform.rotation = Quaternion.Lerp(transform.rotation, lookRot, rotationSpeed * Time.deltaTime);
When they enter a gravity volume I want to take into account the normal rotation of a hit from a raycast and snap the character to it:
if (Physics.Raycast (GlobalVariables.playerPivotPoint.transform.position, down, hit))
{
if(hit.collider.tag == "StaticEnvironment" && GlobalVariables.inGravityVolume == true && GravityVolumeParameters.connectsToFloorStatic == true)
{
//Rotation if floor is down
rayHitRotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
transform.rotation = Quaternion.RotateTowards(transform.rotation, rayHitRotation, rotPullStrength);
}
}
So far using both rotations and overriding the lerp with the RotateTowards is the only way I've managed to get this working however now that I'm trying to make this a whole lot less placeholder I'd like to be able to combine the two rotations and snap to normals while rotating along one axis to look at the mouse.
Anyone know how I can do this? Thanks in advance :-)
Your answer
Follow this Question
Related Questions
Quaternion Rotation On Specific Axis Issue 0 Answers
Changing rotation of Quaternion 0 Answers