Search Unity

5.0.2f Rigidbody2D MovePosition setting the velocity now?

Discussion in 'Physics' started by cjddmut, May 13, 2015.

  1. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    179
    It appears with 5.0.2f that if you move a Rigidbody2D with MovePosition, after the physics tick then the velocity will be set to represent that move?

    Was this intentional? Can we opt out of that behavior? :)
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    I've just checked this as it's a bug. I'll get this fixed now.
     
    Last edited: May 18, 2015
    rbosse likes this.
  3. Deleted User

    Deleted User

    Guest

    Hi, I'm using the last version of Unity (5.2.0f3) and this is happening again. When I move a Rigidbody2D using MovePosition it sets the velocity as well so when I stop moving the GO it keeps moving. Is this a bug again?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    The original bug was fixed in 5.2.0a3 and so should be included in 5.2.0f3.

    The original bug was that the linear velocity wasn't restored after the move had completed. Is this what you're seeing?
     
  5. Deleted User

    Deleted User

    Guest

    I think so. I'm moving my character around the level using rigidbody2D.MovePosition(newPosition) everytime I move the left stick of my controller. It works fine but when I release the stick the character keeps moving using its linear velocity (which I suppose has been set by MovePosition) until it stops by the linear drag (If I set this to a higher number it stops right after releasing the stick but I think this is just a workaround because MovePosition should reset the velocity after the fixedUpdated when I stop moving the character right?)

    Edit: I've just tested it with Unity version 5.1.3f1 and it works perfect. Same project, same scene and scripts and the rigidbody2D runs smoothly and stops when I release the stick. Hope it helps you with this issue
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    I can confirm that the fix is now not in the source for the 5.2.0f3 release but was in 5.2.0a3. I am investigating why this change go 'stomped' on and will rectify the issue ASAP.
     
    Deleted User likes this.
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Darn it. Confirmed that this change has been stomped on by other merges.

    I'll recommit the fix now and get it into the patch release system ASAP.

    Sorry for this problem. This bug is determined to come back and haunt me!
     
    Deleted User likes this.
  8. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Personally I would like the feature (bug).
     
  9. Deleted User

    Deleted User

    Guest

    Thanks a lot for your help MelvMay :)
     
  10. Drakkoon

    Drakkoon

    Joined:
    Mar 7, 2015
    Posts:
    1
    It seems to be in 4.6.8p1 also. I'm not sure when it was introduced, but I know it wasn't there in 4.6.2. Could you check if it's possible to have the fix backported to the 4.6 branch please?
     
  11. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Is this fixed in 5.2.1? Not seeing anything in the release notes, so assuming no..
     
  12. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Hi Mel - curious which patch this is going to be in? I had assumed it would have made it into 5.2.1p1, but it doesn't look like it.

    Thanks.
     
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    It went into our main repository for 5.3 a long time ago but it's taken a fair while to land into the 5.2 patch release branch. I saw a merge request today on it so it shouldn't be too long now. Holidays, events etc have caused a huge delay for which I apologize.
     
    hippocoder likes this.
  14. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Thanks for the update, appreciate it.
     
  15. Nuklettin

    Nuklettin

    Joined:
    Apr 27, 2013
    Posts:
    1
    Hey admin imma real beginner. Im trying to use GetComponent<Rigidbody2d>.velocity but it says "?" at description thing when i write down velocity. the code is like that so you get the problem maybe:
    float rigid = GetComponent<Rigidbody2D>;
    rigid.velocity = new Vector2 (hareket * maxSpeed, rigid.velocity.y);

    this thing was in one of unity's tutorials ( in 4.3 it was rigidbody2D code for GetComponent one so i changed them) and it errors halp pls xD
     
    Last edited: Oct 1, 2015
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Please don't hijack threads like this. Please start your own thread about your subject.
     
  17. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    The fix for Rigidbody2D.MovePosition has now landed into the 5.2.1 patch 3 branch so expect it in that release which I believe will be out next week.

    Again, sorry for the pain this may have caused.
     
  18. beppim

    beppim

    Joined:
    Jul 2, 2015
    Posts:
    58
    It might seem awkward but I landed on this forum page that describes a bug, because what I need is the exact behaviour of that (fixed) bug :D
    Being specific: I use Rigidbody2D.MovePosition on an object when it is dragged by the user. I want the object to continue its travel when the user lifts his finger, keeping its velocity and dealing with normal 2D physics (mass, drag, forces and so on). How can I do it? Should I use something different from MovePosition? Can I intercept the actual object's velocity and force it after the finger is lift?
    Thank you
     
  19. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    You can perform what 'Rigidbody2D.MovePosition' does yourself as it's a trivial calculation and is only a helper.

    The thing is, the velocity it produces is the velocity required to move to the specified position in a single fixed-update. It's unlikely you'd want to maintain that. For dragging objects around, you're far better off using the TargetJoint2D which alters the Rigidbody2D velocity.



    Nevertheless, the calculation is simple and you can do it yourself:

    Code (CSharp):
    1. body.velocity = (moveToPosition - body.position) * Time.fixedDeltaTime;
    The Rigidbody2D.MovePosition saves the velocity ready to be restored later and it also temporarily sets the Rigidbody2D.drag to zero so that doesn't change the velocity and thus stop it getting to the target position.

    Hope this helps.
     
    Last edited: Mar 4, 2016
    beppim likes this.
  20. beppim

    beppim

    Joined:
    Jul 2, 2015
    Posts:
    58
    Marvelous, many thanks! I will try TargetJoint2D.
    Altering manually the velocity is something tricky because, if I understand well, keep the memory of the previous two frames positions, right? So in the frame in which the object is ungrabbed, the velocity is altered to match the previous two frames, not the current frame position, because at this time the velocity has already been reset by the MovePosition method.
    Uhm, nevermind, thanks.
     
    Last edited: Mar 4, 2016