- Home /
How can I pivot an object? Unity2D
This is my first post asking questions so sorry if I didn't give enough information. I have an object (Red) that needs to stay within a certain distance of another object (Blue). when I press a button, AddForce is applied to the bottom of the object and when it is in the air it inherits the rotation of the stick. The problem is, is that the object flies away from the stick. Is there a way to lock a position relative to the way the object is facing kind of like using transform.right? .
Answer by UnityM0nk3y · Mar 09, 2021 at 12:43 PM
Have you tried using a Relative Joint 2D/Distance Joint 2D?
Switch off your current "inherit code".
Ensure all objects have a Rigidbody2D, and "0" gravity if so desired.
On your main object:
Click "Add Component".
Select Physics2D -> Relative Joint 2D OR Distance Joint 2D.
Drag the object you want into "Connected Rigid Body".
The object should now stay a certain distance away, at all times.
Thank you soooo much! You have made my entire day and week! I am so happy this works perfectly! For anyone else, the distance joint work both ways so I could have it on both game objects and rotate both of them while the relative joint only worked one way.
Monkey happy to help!! Good luck with the project!! :)
Answer by patrickjong123 · Mar 09, 2021 at 06:34 PM
You can pivot an object in the Editor in the transform section. If you want to combine them, simply put them in an empty game object together