So for a simple little weapon viewmodel, i wrote this code to add offset to the rotation while still applying the slerp with the offset. I can do this with transform (not slerp however) fine but not rotation. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class followcam : MonoBehaviour { public Transform targetcamera; public Vector3 offset; public Quaternion rotationOffset; public float rotationSpeed = 30f; void Update() { transform.position = targetcamera.position + offset; transform.rotation = Quaternion.Slerp(transform.rotation, targetcamera.rotation, rotationSpeed * Time.deltaTime); // Trying to add RotationOffset to the new result } }
It's generally helpful to post what you tried. Makes it easier to figure out where someone went wrong. My guess is that you were trying to combine the rotations with a + sign. To combine two Quaternions into a single rotation, one multiplies them. Note that multiplication of Quaternions is not commutative; A * B is not the same as B * A. The second rotation is applied relative to the reference frame of the first. For instance, if your object's current orientation is R, and dY is a rotation around the Y axis, then setting your rotation to (dY * R) will rotate the object around the global Y axis, while setting your rotation to (R * dY) will rotate the object around its own Y axis.
Okay, so if you view the attached video, when the game is stopped; i want it to slerp to that position, but when i start the game, i get the wanted result execpt for the rotation being weird, i want to apply an offset to the finished result, i tried doing targetcamera.rotation * rotationoffset and vice versa, but to no avail.