Hello, i have this problem:
I want to force one object to follow the second object parent-like, but without rotation.
I have this code
#pragma strict
var target:Transform;
var x:float;
var y:float;
var z:float;
function Start () {
}
function Update () {
//takes targets position and modifies it
transform.position=Vector3(
target.position.x-x,
target.position.y-y,
target.position.z-z
);
}
but I don’t think it’s a good solution for this problem. Any ideas?
This is actually the easiest solution. You might want to use LateUpdate instead of Update() this will ensure that the “parent” object is on it’s final position for this frame.
Also your offset should be also a Vector3 so it’s much simpler:
var target : Transform;
var offset : Vector3;
function LateUpdate () {
transform.position = target.position - offset;
}