Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

rigidbody position offset?

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

  1. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    150
    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:
    1,493
    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.