Hello, I am trying to get a perfectly circular orbit around an object that works just like transform.rotateAround but with a rigidbody and forces. I have tried methods from other threads but the answers I got from those were unable to create perfect circular orbits that you could adjust the distance between the two objects and the velocity. I want to be able to have orbits that are pretty close to each other. Does anyone have an idea on how to create this system?
Hi I was working on a similar problem recently, I never got to complete it however I think by using Mathf.sin and Mathf.cos to get your x and y coordinates you could hopefully use add Force to travel in a circle. Have a look at this thread it’s not the same problem but shows how to get the points for a circle c# - Draw circle around gameobject to indicate radius - Game Development Stack Exchange
Hope this helps
1 Like
Thank you for helping, I figured it out. Use this code on a rigidbody and it should work.
Quaternion q = Quaternion.AngleAxis (orbitSpeed, transform.forward);
rb.MovePosition (q * (rb.transform.position - target.position) + target.position);
rb.MoveRotation (rb.transform.rotation * q);
7 Likes