- Home /
Rigidbody and collider controlled by 2 gameObjects
Hi, I want to create a rigidbody and collider that is controlled by 2 gameObjects at the two ends like in the below image:
The two gameObjects can move freely in space, and the Collider must update accordingly. How can I do it?
Answer by Berenger · Jan 08, 2015 at 11:23 AM
You know the center (go1's pos + half the vector from go1 to go2), that's the position.
You know distance between them, that's the size.
You know the direction from one to another, that will help find the rotation.
I guess I will have to use Update() to always update the middle gameObject's size, position and rotation, right?
That would be the easy way yes. The best way is to update the middle go only when one of the two other object has moved. Unless they move constantly, then Update's fine. And it's not that much of a complicated algorithm, so it's not going to weigh that much on the fps.