- Home /
Problem with Vector3 position.
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!
#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;
}
}
}
Answer by Mentalcase · Dec 30, 2013 at 07:43 PM
I figured it out. Accidentally had the object in an empty game object with a strange position that should have been 0,0,0.
Your answer
Follow this Question
Related Questions
transform.position not adding correctly with a Vector3 1 Answer
Object doesn't move 2 Answers
How to use a Vector3.MoveTowards and the resulting position as an input for a normalised BlendTree 0 Answers
Get an Object to move to a Position for a Fixed time 2 Answers
I need help on my parented Collider2D and Vector 3 Script 1 Answer