Im having a problem even understanding exactly WHY this is happening but basically : i have two objects, object A and object B. now object B moves at a constant force of lets say, 3 unity objects per second (not quite sure as i can’t be bothered to do the math lol but its not important). object A has a character controller and when A is moved, object B follows. the problem however is that object B doesn’t snap (as tho it were a child) it laggs slightly behind. (the faster object A travels, the further object B falls behind). my current thoughts on the matter, is that object B’s update script (where it tells transform.position to = A’s transform.position) is happening on the frame After A has moved. I can’t figure out exactly how to fix this, if theres some sort of order or something to it but any help would be appreciated!
if you need them, here is the script on object A (the character controller script)
var movementSpeed : float = 5f;
var cc : CharacterController;
function Start () {
cc = GetComponent(CharacterController);
Cursor.lockState = CursorLockMode.Confined;
Cursor.visible = true;
}
function Update () {
var forwardSpeed : float = Input.GetAxisRaw("Vertical")*movementSpeed;
var sideSpeed : float = Input.GetAxisRaw("Horizontal")*movementSpeed;
var speed: Vector3 = new Vector3(sideSpeed,0.0f,forwardSpeed);
//speed = transform.rotation*speed;
cc.Move(speed*Time.deltaTime);
}
And the script on object B :
#pragma strict
var target: Transform;
var playerobj : Transform;
function Start () {
}
function Update () {
var targetPos : Vector3 = new Vector3(target.position.x,this.transform.position.y,target.position.z);
this.transform.LookAt(targetPos);
this.transform.position = playerobj.position;
}
Finally, ive tested so far: moving object B’s transform action above the lookat function (to no avail) i’ve also changed the speed of object A and i did notice object B fell much further behind…also i’ve tried correcting for movement but i’d rather avoid having scripts stupidly long lol.
thanks anybody who can give me a suggestion to this obnoxious problem!