I want to make it so that two objects freeze position in relation to each other with a line between them when they get in range of one another (or in other words, bond to each other), but still be able to move apart if it gets bumped by another object. I also want there to be able to be more bonds, but only if a variable ( hasBonds
) is less than another variable ( maxBondNum
) for each object. And for each bond, I want hasBonds
to increase by one, then decrease by one if the object leaves the radius. And when hasBonds
is equal to maxBondNum
, I want it to ignore all other objects as far as bonds are concerned. All of these objects have rigidbodies, and I need it to work for every object of this type without the game grinding to a halt when there are a lot. I also need a line that moves with the objects, and is fixed to the objects’ centers. I have tried line renderer, but I can’t get it to work.
Hello.
There are basicly 2 ways to make multiple objects “freeze relative position” between them.
- Using Child/parent in hicheracy
- Using Joints
Depending on what you need, whats your hicheracy objects, rigidbodies, etc… you will need one or the other way. Child/Parent is more simple, but needs more coding if want “complex” behaviour.
If pretend to “activate / desactivate” the relative position freezing, most probably best way is using joints, but you need to learn how to use them.
I recommend you to watch some tutorials about joints (there are different tipes, depending on what you need) and of course know how child/parent transfoms relations works, so you can decide correctly wich way to proceed.
Most probably you need one of this two joint types:
Good luck!