Search Unity

Weird behaviour I found with Rigidbody

Discussion in 'Editor & General Support' started by n0mad, Mar 28, 2012.

  1. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    1) What happened
    Rigidbody.MovePosition() doesn't work if animation.animatePhysics is set to true before Play(), but does work if it's set at Runtime.

    2) How can we reproduce it using the example you attached

    - Create any object that would have a quick move forward animation.
    - Attach rigidbody + boxcollider to it

    A)
    - check its animation.animatePhysics on TRUE before playing
    - try to use MovePosition(), it doesn't move anything (used in FixedUpdate of course)

    B)
    - check its animation.animatePhysics on FALSE before playing
    - MovePosition() does work but ...
    - ... read the "quick forward moving" animation just in front of the other rigid object
    -> it passes through

    C)
    - check its animation.animatePhysics on FALSE before playing
    - after having hit Play, put animation.animatePhysics on TRUE in Inspector
    - MovePosition() does work and ...
    - ... read the "quick forward moving" animation just in front of the other rigid object
    -> it is stopped by the object correctly.


    I don't understand this behaviour at all ...



    Case 454280


    edit :

    D)
    - check its animation.animatePhysics on TRUE before playing
    - try to use MovePosition(), it doesn't move anything
    - check its animation.animatePhysics on FALSE while playing
    - MovePosition() still doesn't work, as it should because animation doesn't have any other incidence on physics
     
    Last edited: Mar 28, 2012
  2. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    I found a (weird) workaround :

    - check animation.animatePhysics on TRUE before playing
    - try to use MovePosition(), not in builtin FixedUpdate(), but in a Coroutine() yielding WaitForFixedUpdate() instead
    - MovePosition() does work, and reading the "quick forward moving" animation just in front of the other rigid object
    -> it is stopped by the object correctly.

    In the docs it is said that yielding WaitForFixedUpdate does wait for all FixedUpdate functions to have performed, so this behaviour is logical as animatePhysics = true puts animations calculations inside the FixedUpdate loop.
    But .... This means that these animations calculations are not put at the start of the FixdUpdate, but at the end, which completely nullifies the goal of setting animatePhysics to true .........

    So I guess it is either a bug, or at least not designed to be like this at all.


    edit : Add an even weirder finding : So everything works with this setup. But as soon as I put the rigidbody I want to use MovePosition with on Interpolate.NONE, then MovePosition() doesn't work anymore .................
    Seriously ??
     
    Last edited: Mar 28, 2012
  3. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Well, I finally ended up completely leaving the builtin Physics collision system. Going back to my own.
     
    twda likes this.