Search Unity

Maximum Rigidbody2D velocity?

Discussion in '2D' started by SandwichDev, Nov 16, 2013.

  1. SandwichDev

    SandwichDev

    Joined:
    Nov 16, 2013
    Posts:
    2
    I'm noticing when I am changing the value of the velocity on a Rigidbody2D object it gets capped at -100. Any value lower than that I can set, but when the physics runs it just uses -100 and changes the value to -100.

    Is this a hard limit or is there a setting to adjust this? I could get around this by scaling my whole project down but that seems like a lot of work when I don't see a real reason about it would need to be capped at these values.

    Any ideas?
     
  2. joethephish

    joethephish

    Joined:
    Nov 16, 2013
    Posts:
    5
    I'm finding the same, after attempting to use pixels as game/physics units, which makes the world scale much larger. Any help would be much appreciated!
     
  3. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    I think your best option is scaling your world down. This issue seems to be common in the box2d world when people try using 1:1 ratio for pixels to world units. I believe the default values exist to prevent such issues with the physics system. You might try messing with the Physics 2D settings in the project settings area.
     
  4. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Ugh - yeah, I've just run into this too. Ideally Unity would just expose whatever pixels-to-unit ratio it is passing down to Box2D, so that the user could set it on a per project basis. For now though, looks like scaling down everything is the only viable solution.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Unfortunately, many of these things such as maximum velocity per physics update are compile-time constants in Box2D and are therefore not available to be changed dynamically at runtime however, we are looking into which of these constants are can expose which wouldn't causes internal Box2D problems. This however requires us to modify Box2D directly, something which we are trying to avoided or at least limit.

    I think it's fair to say that you can expect us to expose such "constants" in the future.

    Hope this helps.
     
  6. Shnayke

    Shnayke

    Joined:
    Mar 29, 2013
    Posts:
    11
    @MelvMay - Just came across this thread and issue in my own game. I know this may be a tough one, but is there any timeframe on when that might be released? Like, months? Or years? Next update? Or backlogged?
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    I have recently implemented (exposed) many of the Box2D global properties that were previously fixed (compile-time) so you can configure them in the 2D physics manager and change them dynamically at runtime.

    The following have gone into an internal alpha release.
    • Velocity Threshold (b2_velocityThreshold)
    • Max Linear Correction (b2_maxLinearCorrection)
    • Max Angular Correction (b2_maxAngularCorrection)
    • Max Translation Speed (b2_maxTranslation/b2_maxTranslationSquared)
    • Max Rotation Speed (b2_maxRotation)
    • BaumgarteScale (b2_baumgarte)
    • BaumgarteTimeOfImpactScale (b2_toiBaugarte)
    • TimeToSleep (b2_timeToSleep)
    • LinearSleepTolerance (b2_linearSleepTolerance)
    • AngularSleepTolerance (b2_angularSleepTolerance)
    Hope this helps.
     
  8. a-lomo

    a-lomo

    Joined:
    Aug 5, 2012
    Posts:
    12
    When can we expect this? Is there any way we can ensure this for a release soon? Our project heavily depends on 2D physics and scaling everything down would be incredibly difficult at this point.
     
  9. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Yes, I would like to know too when we can expect this and also, I would like to know if some of these items will provide a way to disable or increase the maximum angular speed that currently affects the box2d physics and also if there will be a way to disable/increase that limit only for some objects (the wheels of my vehicle :) ).

    Thank you in advance and good job!
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Unfortunately I cannot give you dates of releases no matter how much I wish I could! All I can say is that you won't have to wait until the next major release or anything crazy like that.

    It's in the list you quoted i.e. "Max Rotation Speed". I also reference the Box2D internal constant so you can look it up in the Box2D SDK i.e. "b2_maxRotation:". There's no disabling, you'd just set a sufficiently high rotation speed. Of course, changes like this will lead to problems with people substituting meters for pixels and using supersonic speeds and expecting a good simulation but I did it because everyone should have a choice on what these "constants" are.
     
  11. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Thank you for your reply. Yes, that's quite obvious, I just wanted to make sure we're talking about the same thing... it seems there will be no per-object configuration of 'Max Rot Speed" then... no big deal, although the other engine (physx) allows it, I think I could find a compromise between allowing my wheels to rotate fast enough and not destroying the simulation for other objects.

    I was thinking about making something like the wheel collider using rays but it's not a good approach for a 2D game because you know, the 'ray' is only a single 'contact' point and, besides being a quite decent approximation for most 3d games and working okay for some 2d, I don't want it for my game, so, the next option is perhaps to create a circle collider (a static one) to use as the wheel and analyze its contact points and apply forces according to the contact points normals... it's quite easy on paper, you divide the 'motor' force by the number of contact points and apply the forces on each, however, last time I've played with contact normals the result were quite funky.

    I think a way to simulate a wheel would be better than messing up with the 'max rot speed', but I couldn't find a way to get it working decently.

    Thanks.
     
  12. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Any update? I upgraded to 4.x, added my first 2D physics behavior, and hit the 100 m/s max velocity by the end of the day. Course, it took me about an hour to figure out it was a Unity/Box2D limitation.

    PLEASE UPDATE the Rigidbody2D.velocity documentation - add 'Box2D uses a cap on velocity of 100 m/s - while we work to increase that, you may consider rescaling all of your models to fit this limitation.' Searching the net shows 100s of posts on this - let's be good chaps and save the next folks some heart-ache.

    Gigi.
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    While we're updating the docs please update:

    https://docs.unity3d.com/Documentation/ScriptReference/Physics2D.Raycast.html

    In particular if (hit != null) {

    1. This appears to be pretty much useless.
    2. People should be checking it as a bool instead, or if collider is null.

    The reason it needs documenting is because Physx will be null and this won't be. It's inconsistent and confusing for new users learning.
     
  14. Ted-Chirvasiu

    Ted-Chirvasiu

    Joined:
    Sep 7, 2010
    Posts:
    381
    I'm really curious about the update too... It is quite crucial for my project.
    Exposing those variables would be a life saver.
     
  15. rattlehead57

    rattlehead57

    Joined:
    Oct 11, 2013
    Posts:
    2
    I guess this still hasn't been added?

    It's a real pain. I spent a few hours last night trying to figure out what was happening.

    Any timeframe on when this will be fixed/exposed?
     
  16. Ted-Chirvasiu

    Ted-Chirvasiu

    Joined:
    Sep 7, 2010
    Posts:
    381

    Haven't tested it yet, but as far as i see, they are exposed in 4.6.0f3. Try going to Edit->Physics 2D->Max Translation Speed and increase it. That should do it.