im trying to make an empty GO stay half way between two moving objects, but i cant figure out how to tell the empty GO the positions of the other to objects
how do i find where the other two objects are in world space to tell my empty GO??
im trying to make an empty GO stay half way between two moving objects, but i cant figure out how to tell the empty GO the positions of the other to objects
how do i find where the other two objects are in world space to tell my empty GO??
Every gameobject has a transform component so you should just be able to reference: (gameobject).transform.position to get the positions of each of your objects.
i cant get it to work, is it supposed to look like this??
var box1dist=(box1).transform.position;
it keeps telling me box1 is unknown
You want to take those parentheses out.
–Eric
it still says unknown identifier, is this in the docs some where cause i couldn’t find it, i could only find how to find the position of the object the script is attached to
Actually the parentheses aren’t an issue; it’s unusual but you can use parens like that.
What you need to do is to declare box1 like this:
var box1:Transform;
var box2:Transform;
function Update() {
//set position to the position of box1
transform.position = box1.position;
//set position to halfway between the two objects
transform.position = Vector3.Lerp(box1.position, box2.position, 0.5);
}
In the script’s Inpector panel you’ll see box1 and box2; drag your objects from the heirarchy onto these variables.
This is in one of the tutorials somewhere, I think the FPS one.
ahh thank you that works perfectly