Search Unity

rigidbody position offset?

Discussion in 'Physics' started by Innovine, Oct 10, 2018.

  1. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    I have some code which moves a transform with a rigidbody attached. It seems to work fine, and I can move it to a target using a PID controller which calls AddForce() and all is working OK. But if I also perform a few AddForceAtPosition()'s then I start to see a drift, and when I move it to what should be the rest location, it arrives a little bit off to one side, as if it's developed a local transform or an offset in some way.

    Any suggestions on what's going on here?

    I am calling rigidbody.AddForce(), rigidbody.AddForceAtPosition(), and I also directly assign values to transform.rotation. Can that be the culprit? Perhaps rigidbody.MoveRotation or rigidbody.rotation are more appropriate..?

    Is there a difference between transform.rotation and rigidbody.rotation besides performance and colliders, which could result in a translational offset?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Yes. If you are writting to them directly they are called at different time. Transform.rotation/position is written at given frame. While in case of RigidBody, is called when physics is calculated. So you will see differences, or even can experience jittering.

    Did you try use AddRelativeForce? Are you sure you have adding force at right position? With right force vector?

    Try use Debug.DrawLine / Ray, to see, which and where force is added.