Hello,
I’m creating a scene where you can walk a character along a path. I am trying to get the camera to follow the character at a 90 degree angle from his forward direction, which is constantly changing as he moves.
Here is a demo, use A and D to move) : Character Demo
This is the code that I have so far, which is attached to my camera, is:
var cameraYOffset : float = 10f;
var cameraDistance : float = 20f;
function LateUpdate () {
if (target) {
// Find the new camera position, 90deg right from target forward
var rightPos : Vector3 = Vector3.Cross(Vector3.up, -target.forward) * cameraDistance;
rightPos.y += cameraYOffset;
transform.position = rightPos;
// Now look at the target
transform.LookAt(target);
}
}
So this kind of works, but you’ll see as the character walks further along the path (towards the end mostly), the camera sort of stays still while the character walks off into the distance. I can’t figure out why this is happening. Wondering if anyone has any ideas…
Ryan