Search Unity

Transform.RotateAround with Rigidbody and Physics

Discussion in 'Physics' started by StephenRJudge27, Dec 11, 2018.

  1. StephenRJudge27

    StephenRJudge27

    Joined:
    Sep 2, 2015
    Posts:
    24
    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?
     
    halfblue3 likes this.
  2. N_Murray

    N_Murray

    Joined:
    Apr 1, 2015
    Posts:
    98
    StephenRJudge27 likes this.
  3. StephenRJudge27

    StephenRJudge27

    Joined:
    Sep 2, 2015
    Posts:
    24
    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);
     
    halfblue3, path14, roointan and 4 others like this.