Hi, I’m having a problem getting the right position from an object. I am still new to Vector3 and am confused as to why the closed position is different from the position of my object. This script should slide the door open on-click to the specified coordinates of ‘open’. I believe that it should work except that the ‘closed’ variable receives completely different parameters than what the position says. Any help would be highly appreciated, thank you!
[19933-screen+shot+2013-12-30+at+11.42.06+am.png|19933]
#pragma strict
// Check if door is open or closed
var isOpen : boolean;
// Variables for open and closed position values
var closed : Vector3;
var open : Vector3;
var endPoint : Vector3;
var duration : float = 1.0;
private var startPoint : Vector3;
private var startTime : float;
function Awake (){
}
function Start () {
isOpen = false;
closed = transform.position;
startPoint = closed;
endPoint = closed;
startTime = Time.time;
}
function Update () {
transform.position = Vector3.Lerp(startPoint, endPoint, (Time.time - startTime) / duration);
}
function OnMouseOver (){
if (Input.GetMouseButtonDown(0)){
if (isOpen == false){
startPoint = closed;
endPoint = open;
isOpen = true;
}
else {
startPoint = open;
endPoint = closed;
isOpen = false;
}
}
}