# how to set distance between two objects constant?

Hi,

I’m trying to make one object rotate around another using RotateAround.

When the rotating object collides with another object, the rotating object goes around the collided object automatically.

I want the rotating object to have a fixed distance at all times regardless if it collides with another object.

For example, I have a solid fireball that is twirling around the character, when the ball hits an object. it should stop and not auto try going around it or go through it (keep distance fixed between fireball and character controlling the fireball.

I have try different combinations of colliders, distance joint and on enter triggers but couldn’t the solution. I’ve been working on this for days.

How should I go about doing this?

That should be a DistantJoint2D, in 2D physics. Why isn’t that working for you?

I rotate the sphere around the smaller cube, when it hits the larger cube, the sphere goes along the edge of the large cube and eventually goes around it if I keep rotating it. How to make it not go around after hitting the large cube?

edit:
Im using transform.RotateAround with distance Joint.

2nd edit:
I’m thinking if I’m able to get the distance between the smaller cube and the sphere to be constant, this way it should prevent the sphere from moving around the larger cube. How do I make the sphere not go around the larger cube? More like its blocking the sphere from moving at all.

I have resolved this by doing a workaround.

setup:
distance joint, rigidbody on the object rotating around another object

1. calculate the distance between two objects using Vector3.Distance…
2. if the distance is within the desired valued, transform.rotatearound…
3. else tranform.position = new Vector3(transform.position.x - value… this will keep pushing the object backwords so it cannot wrap around the blocked object.

FYI… the DistanceJoint2D currently has a bug in it which causes it to act like a RopeJoint instead. This will be fixed in the next major release.