Search Unity

2D platformer, 4.6 to 5, weird physics with moving platforms

Discussion in '2D' started by GiyomuGames, Mar 6, 2015.

  1. GiyomuGames

    GiyomuGames

    Joined:
    Jan 12, 2015
    Posts:
    80
    Hi everybody,

    I updated 2D platformer project from 4.6 to 5. I corrected basic issues like restoring my x and Y snap settings and also unchecking "apply root motion" on the animator (which caused my character and enemies to fly instead of standing still).

    I have only 1 issue left: now when the player is walking/running on a moving platform his movements are slow. It looks like the moving platform is sticky even though I use the exact same material for the colliders of all platforms.

    Anyone has experienced that? Any idea how to fixe it?
     
  2. samrad

    samrad

    Joined:
    Feb 10, 2014
    Posts:
    6
    I'm seeing a similar thing where i have a space shooter and the enemies are moving very very slow ... i'm using gravity to let them fall and setting a velocity on them but it appears to not really move them, although it was before.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,450
    I am not aware of any issues like this, nothing fundamental has changed between 4.6 and 5.0 to cause this. Could you please submit a bug report with a project to reproduce this so I can take a look? Ideally something I can load in 4.6 and 5.0
     
  4. AlenBrk

    AlenBrk

    Joined:
    Feb 17, 2014
    Posts:
    33
    Hi, if u have animated enemies, check if the "Apply Root Motion" is active on the animator.
    Maybe deactivating will help.
     
    samrad likes this.
  5. samrad

    samrad

    Joined:
    Feb 10, 2014
    Posts:
    6
    Thanks for the help!

    Ah thanks for the help, I unchecked "apply root motion" on my enemy prefab and everything worked as expected again! I have a looping animation on them that grows and shrinks them as they move around, so that with the root motion must have been the culprit.

    Everything else has appeared to transferred over smoothly from 4.6->5, so that's great :)

    Thanks!
     
  6. AlenBrk

    AlenBrk

    Joined:
    Feb 17, 2014
    Posts:
    33
    You are welcome... yes i can confirm that too.
    My only "issue" was the "root motion".

    Br, Alen
     
  7. GiyomuGames

    GiyomuGames

    Joined:
    Jan 12, 2015
    Posts:
    80
    MelvMay: thanks a lot in advance! I have just submitted the bug report. The project works on 5 (because this is where I have the "bug"), but I believe you will be able to open it with 4.6. This being said the problem is visible without necessarily opening on 4.6: you will see that the colliders of the moving platforms and non-moving platforms have the same material but the player kind of sticks on the moving platforms. I haven't changed any line of code regarding moving platforms or even player movements since the 4.6 version.

    The others: glad you could solve your issue. I did mention the "root motion" thing at the beginning of my post though! ^^
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,450
    Can you please provide me with the case number, thanks.
     
  9. GiyomuGames

    GiyomuGames

    Joined:
    Jan 12, 2015
    Posts:
    80
    Yes of course! Really sorry, I thought maybe you could track it with my id.
    Here goes: 678212

    Thanks a lot in advance for any idea on what's happening.
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,450
    Thanks, I'll take a look shortly for you.
     
    GiyomuGames likes this.
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,450
    It would help if we could get a greatly simplified set-up here as there's a lot going on for someone not familiar with all the script here. It would seem it's related to the fact that you're repositioning a dynamic rigid-body (the player) by modifying the transform against a static collider that's also being repositioned (the platform). Without this, you can move normally. Really not sure how that is affecting your controllers.

    It's kind of irrelevant what happens in 4.6 against 5.0 in terms of solving the issue. It's possible that the set-up is relying on some broken behaviour that was fixed, not sure. Certainly, I can see that repositioning the player is causing overlaps of the platform which the physics system is trying to solve (which is why repositioning is a bad idea). As to why it slows down, not sure. Maybe the impulses solving the overlap are going against the player movement forces at a wild guess.
     
    GiyomuGames likes this.
  12. GiyomuGames

    GiyomuGames

    Joined:
    Jan 12, 2015
    Posts:
    80
    Hi MelvMay,

    Thanks a lot for looking into this! I am very very sorry for my late reply, I was waiting to receive an email notification for a new post so I actually just saw your message now. Also thanks a lot for taking time to read through my code when indeed I didn't make a simplified set-up. I'll make sure to upload a simpler project next time.

    If I understand correctly, repositioning a dynamic rigid body (i.e. not kinematic) to follow the platform is not a good idea even if it was working on 4.6. I guess I should have seen that coming. Rigid bodies should only be moved using forces / updating velocities and the position should be taken care of by the physics engine (I'm writing this just so you can correct me if I am wrong).

    Moving forward, I have removed all the code where I was updating the player's transform directly. Now I add the platform's velocity to the player's velocity and everything is working fine for a horizontally moving platform (I had to put a material with 0 friction on my platform though). I couldn't make it work properly with platforms moving up and down: the player is slightly entering inside the platform when it's moving up, and floating slightly above it when it's going down. Regardless of my code, if you could give me an idea / direction regarding the best practices on moving rigid bodies along with platforms it would be great! (I did a search here and on Google but many links where outdated apparently)
     
    N3ms likes this.