- Home /
Constant distance between two gameobjects
Is it possible to set it so two objects that are both affected by physics are a fixed distance between each other programmatically (On a 2D plane)? I basically want it so they are always 10 units away from each other. I'm sure that I could do it with joints but i'd rather not and if possible do it like:
if(Vector2.Distance(PointA, PointB)<10 || Vector2.Distance(PointA, PointB)>10){
// DoSomething
}
But I'm not sure what I could do inside the if statement and how I could scale the x and y values so the hypotenuse/distance is always 10. Does anyone have any ideas?
Comment