Hello. I’m really new to Unity and C#. While going through the guides that people made for third person camera, I came across this script line that people use to place themselves in the back.
public class FollowCamera : MonoBehaviour {
public GameObject target;
public float damping = 1;
Vector3 offset;
void Start() {
offset = target.transform.position - transform.position;
}
void LateUpdate() {
float currentAngle = transform.eulerAngles.y;
float desiredAngle = target.transform.eulerAngles.y;
float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
Quaternion rotation = Quaternion.Euler(0, angle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}
}
In this code, I see this script line and I don’t get how this works.
transform.position = target.transform.position - (rotation * offset);
I know that you can subtract two positional vectors to get the distance between them but how can one subtract rotational quaternion values from the position which are vector 3 values?
I don’t see them combining since one is about the world position but the other is about the rotation itself. Is the rotation not relative to its own local axes? – like, how does it place you at the back of your target? Wouldn’t mess your position up if you were to just combine them? please explain this to me and how this subtraction works… Thank you!