Need help with relative motion between objects

Hey everyone,

Not sure how to attack this in C#. Basically I need to say: Get however much Object A translates on the X axis, and make Object B translate by the same amount on the X axis (regardless of where object B is located in world space) * .5.

In other words, if Object A moves from 0,0,0 to 5,0,0 (assuming Object B is starting at 8,0,0) I want Object B to move from 8,0,0 to 10.5,0,0. Any ideas?

Many thanks.

It took me too long to figure out that “.5.” wasn’t supposed to be some weird emoticon.

this one’s easiest to explain by sample code. The key is to track where its position from the previous frame and subtract it, so you can alter the slaved object accordingly.

public Transform masterObject;
public Transform slaveObject;
public float movementFactor = 0.5f;

private float lastXObserved = 0f;

void Start() {
lastXObserved = masterObject.position.x;
}
void Update() {
float xDelta = masterObject.position.x - lastXObserved;
slaveObject.position = new Vector3(slavePosition.position.x + movementFactor * xDelta, slaveObject.position.y, slaveObject.position.z);
lastXObserved = masterObject.position.x;
}
1 Like

Thanks! This makes sense. I’ll give it a shot!

Update: That did the trick! Thanks again.