Click a cube to move player over to that position & rotate player to face fixed point

  • what i want to happen is that you see a cube, click it, the First person Controller jumps over there and whilst thats happening, it rotates around to point at a fixed object in the distance

I copied and altered some of Duck's code from the question: 'Click 3D objects (markers) in the distance, causing the camera to snap to that location'. My script added to the cube works BUT the camera ends up facing the wrong way when the script is over. Whats the fix?

script for the cube:

function OnMouseDown() {
var player = GameObject.FindWithTag("Player");
var startTime = Time.time;
var startPos = player.transform.position;
var startRot = player.transform.rotation;
var targetPos = transform.position;
var  targetRot = transform.rotation;

targetPos.y = player.transform.position.y;  // preserve cam's height

while (Time.time < startTime+1) {
    var i = (Time.time - startTime);
    player.transform.position = Vector3.Lerp(startPos, targetPos, i);
    player.transform.rotation = Quaternion.Slerp(startRot, targetRot, i);




The cube also needs another script which points it towards the fixed point:

var target : Transform; 

function Update () { transform.LookAt(target); }

  • any suggestions gladly received and also any links to good scripting tutes!


The problem could be the Quaternion.Slerp(startRot, targetRot, i). This statement change player’s rotation to the rotation of the object (cube here). Vote me up so that I know you still need help on it.