- Home /
Question by
VerrucaG · Apr 08, 2014 at 07:14 PM ·
quaternionsnapping
Combining two rotations to look at the mouse while snapping to terrain
Hi all, I've got a transform which is rotating to match the normal rotation of the ceiling whilst in a trigger box called GravityVolume:
if (Physics.Raycast (GlobalVariables.playerPivotPoint.transform.position, up, hit))
{
if(hit.collider.tag == "StaticEnvironment" && GravityVolumeParameters.connectsToCeilingStatic == true)
{
Debug.DrawRay (GlobalVariables.playerPivotPoint.transform.position, up, Color.green);
isOrienting = true;
hitNormal = hit.normal;
}
rayHitRotation = Quaternion.FromToRotation(transform.up, hitNormal) * transform.rotation;
transform.localRotation = Quaternion.Lerp(transform.rotation, rayHitRotation, orientationPullStrength * Time.deltaTime);
I've also got a Vector3 direction from the player transform to the mouse position which I lerp towards when not in GravityVolumes called mouseDirectionFromPlayer:
var lookRot = Quaternion.LookRotation(mouseDirectionFromPlayer);
transform.rotation = Quaternion.Lerp(transform.rotation, lookRot, 10 * Time.deltaTime);
So far I've been unable to combine the two rotations so the player both looks at the mouse and snaps to the normals of the ceiling. Does anyone know how I could achieve this? Thanks
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613142242im_/https://answers.unity.com/themes/thub/images/avi.jpg)