- Home /
How to make two objects mimic each other?
I'm trying to make two rigidbodies mimic each other, if objectA moves forward, ObjectB will move forward the same direction and distance too, if objectA rotates, objectB will rotate too and viceversa, however, if objectA collides with one object I want objectB to act as if it was also colliding, but unless objectB also collides with an object, how can I fix this?
The code is this:
pragma strict
public var target : Transform; public var zdistance = 0.5; public var ydistance = 0.5; public var xdistance = 0.5;
function Update (){
GetComponent.<Transform>().position = target.position + Vector3(xdistance, ydistance, zdistance);
transform.rotation.x = target.transform.rotation.x;
transform.rotation.y = target.transform.rotation.y;
transform.rotation.z = target.transform.rotation.z;
}
I put this script to both objects I want to mimic each other.
Answer by TanselAltinel · Oct 28, 2017 at 02:53 PM
If you are using RigidBody component, do not ever, never, ever move them with changing Transform values.
For movement, set their velocity instead of transform.position, and for rotation do use Quaternion values.