Sorry if someone has already answered this. I've looked and haven't found anything like whats happening to me.
I have a point in space (Vector3) that I want the object to smoothly turn to but I cant seem to make the code work:
function RotateTowardsPosition (targetPos, rotSpd )
{
// Convert the vector2 to a vector3
var target = (Vector3(targetPos[0], 0, targetPos[1]));
// get the current position
var currentPos = transform.position;
var relativePos = target - currentPos ;
var rotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.time * rotSpd);
}
When I run this I get an error stating the the "Object reference not set to an instance of and object" and is states the var target line as where the error starts. Any help would be much appreciated.