Search Unity

2D Physics Roadmap

Discussion in '2D' started by MelvMay, Apr 17, 2017.

  1. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    The following information will soon be added to the Unity Roadmap but I thought it worthwhile adding it here. Note that the information here may eventually get stale and may be removed later. Items in "Research" are likely to go into "Development" for 2017 so just because they are shown there, doesn't mean years until you get them. They'll either appear in the 2D experimental build or a one-off custom build for feedback.
    • 2017.1.0 (beta)
      • Simulation
        • Ability to manually simulate physics using "Physics2D.autoSimulation=true/false" and "Physics2D.Simulate(time)".
    • Development
      • Low Level API
        • Expose low-level collider primitives of circle, edge, polygon & capsule and ability to retrieve from existing Collider 2D components.
        • New 2D collider with ability to be composed of low-level collider primitives.
        • Super fast, primitive intersection tests with batching support not requiring 2D collider components.
        • Gizmo support for primitive collider shapes of circle, edge, polygon & capsule. Useful in visualising/debugging intersection tests.
    • Research
      • Simulation
        • Multi-instance 2D physics worlds.
        • Ability to assign simulation group(s) to Rigidbody2D and simulate specific group(s) and/or calculate contacts for those group(s) only.
        • Expose contact processing allowing users to defer contact solving, enable/disable contacts etc.
      • Performance
        • Asynchronous CompositeCollider2D outline and triangulation.
        • Asynchronous PolygonCollider2D triangulation.
        • Multihreaded simulation.
      • Animation
        • New Animatable 2D Collider that tracks SpriteRender mesh.
        • Explicit Kinematic Rigidbody2D Hierarchy control
      • Joints
        • HingeJoint2D motor "free spin" support.
        • Joint2D anchor local scaling support.
      • Colliders
        • EdgeCollider2D 'adjacent edge' support allowing chaining of EdgeCollider2D together with virtual edges.
        • EdgeCollider2D to EdgeCollider2D collision support.
      • Rigidbodies
        • Transform write-back to planes other than XY using swizzle option i.e. write back to XZ, YZ etc.
        • Customised collision modes allowing alternatives to layer-based detection.
        • Distance based wake-sleep for Rigidbody2D.
        • Wake/Sleep Callbacks.
        • Ability to retrieve all Rigidbody2D, Collider2D & Joint2D.
      • Effectors
        • New asset-based effector behaviour system allowing blending of multiple behaviours.
        • SurfaceEffector2D "speed-up only" support disabling slowing down if surface speed is too high.
      • Materials
        • Full integrated shared physics materials.
      • Fluids
        • LiquidFun Integration
     
    Last edited: Apr 19, 2017
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Very interested! Basics like getting Super fast, primitive intersection tests with batching support not requiring 2D collider components are wonderful.

    I was wondering if this in any way helps with local physics? moving platforms can be tricky / arcade games on vehicles and various moving objects etc with arcade rules mixing with physics are difficult but often needed.

    I do love the entire roadmap though. I see a lot of stuff I'd love to mess with including LiquidFun!
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    It may not come across in the roadmap but my main motivation here is to expose, in a sensible way, as much of the physics as possible so we do not continue creating higher and higher level constructs (effectors etc) but instead provide the ability to create those features yourself. That obviously means being able to do cool stuff in your games but also to the point where we can get much more sophisticated stuff on the asset store. It also means that more and more of the higher level stuff can be provided open-source, completely script driven. I'd like to be in a position where the UI team are where the components are scripts.

    > Expose contact processing allowing users to defer contact solving, enable/disable contacts etc.
    This one alone means that every single effector we have can be done by a user, including the PlatformEffector2D.
     
    luchong12 and npatch like this.
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    That's wonderful for me. Eventually Unity has to stop adding things for people who can't code, especially if visual scripting can access these things you're exposing in future... else you'd be doing nothing but high level work for years to come :)

    Any idea on times? In particular my sense of fun reaches out for LiquidFun for the lava in my 2D game... (and water). I guess we would want an array of these points or at least a starter mesh to do further rendering with, maybe it's rendered with the particle system?
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    No times. I'll keep the roadmap updated. You'll see things transition from "Research" to "Development" then into "Release". I'll also make a lot of noise about each on Twitter as usual which is where you'll see it first with development screenshots and videos typically.
     
    npatch and hippocoder like this.
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Looks like a ton of work ahead of you, so thank you very much!
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    ArthurT likes this.
  8. Momoliz

    Momoliz

    Joined:
    Apr 22, 2017
    Posts:
    1
    thankyou so much friend to make me already join this forum
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Posting here as it might be relevant to future plans...

    @MelvMay currently I find myself needing to see if a gameobject with one or more colliders (components on the same object OR as children) .... are overlapping another complex or simple arrangement.

    I can get this with OnCollisionStay and filter out what I don't need but I'm not sure if this use case is possible now or in the future roadmap. I'll explain the situation:

    I have a bunch of RPG style items such as swords, shields etc, and they all have different colliders, different numbers of colliders and so on, in short they're unique.

    But most of the time they do not need to be simulated, only when they're dropped in the world. Bur when say, a sword is attacking, it needs to know if it's overlapped with a shield, and they both don't have any consistency with colliders.

    So I'm not sure how to best check if the sword hit the shield, and if it didn't, check the sword hit the player and so on. I figure I can do it manually but that is a hell of a lot of colliders to check pairs for against....

    TLDR: need to get a list of other colliders touching my complex gameobject mess of multiple colliders. This https://docs.unity3d.com/ScriptReference/Physics2D.OverlapCapsuleNonAlloc.html is fine, but my objects aren't just made of capsules, so I would have to peform multiple separate Overlap checks for boxes, capsules, circles, each time filtering out results that belong to the same gameobjects.

    I feel that would be asking Physics2D to do a lot of redundant work.
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    Would Rigidbody2D.OverlapCollider work for you in that case? All this really does is iterate all colliders and effectively does Colldier2D.OverlapCollider on each. These are the overlap equivalents of Rigidbody2D.Cast and Collider2D.Cast which allow you to query using colliders without having to deal with their types.

    Note that you can do the iteration yourself using a combination of Rigidbody2D.attachedColliderCount and Rigidbody2D.GetAttachedColliders. The attached colliders may of course be on children. There's also the GetContacts for when you need to know about actual contacts from the last update which removes the need to rely so much on callbacks.
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    That would work fine, how much quadtree work do I need to do to split space up to optimise it, or will it just discard things it won't potentially touch early on? and of course disabled colliders? I realised, I don't know a thing about the optimisations going on with Physics2D! :)
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    Quadtrees? I am not following because I do not follow exactly what you're trying to solve here. The colliders being Cast/Overlap just use the collider shapes as definitions so they need to be enabled (otherwise they do not have shapes) but not simulated as contacts are not relevant.

    It might be worth discussing this on another thread or in a conversation rateher than here.
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    Not a problem, happy to help if you want to take it offline or on some other thread.
     
  15. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    110
    Great to see this roadmap, very good improvements.

    Currently for my project, i heavily used Physics2D.IgnoreCollision(Collider2D, Collider2D, bool), the case is:

    There's a lot of star-ships, each ship composed by numbers of Rigidbody2D, the colliders in same ship will not collided with each other, but they will collide with other ship's. Because the ship count may larger than 32 so i can use layer based filter, there is only Physics2D.IgnoreCollision can works, but it is not elegant(since It is not persistent, more works need to do after collider enabled/disabled etc.).

    So I wondering, if there's a collisionGroup or collisionLayer for colliders or rigidbody, each ship will has a certain group/mask id, the colliders will not collide with same id but will collide with all other which has different id. It will make things easier.
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    I think a method that scales beyond 32 of anything for collision control is something worthwhile, especially if the method could be used for multiple purposes. The "layer" stuff can be very limiting for physics in some scenarios but it's also something we have to keep for backwards compatibilty.

    It would also be nice if we could have something that could be multi-purpose. For instance, being able have some "named" group then be able to use as many of those as you like for collision detection, queries, simulation etc.
     
  17. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    110
    This sounds very cool. Glad to see it.
     
  18. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    110
    Can't wait to try the Low Level APIs, is there a estimated date?
     
  19. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,496
    Not going to give out any estimates because they're useless until the feature is at least beta quality and has been reviewed internally. As always, I'll try to push out dev videos/images as it emerges and maybe push to experimental build if appropriate.

    I am working on the low-level primitive work now though. It has most of my focus.
     
  20. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    110
    Cool, If you push out dev videos/images, I would be very excited to read them, and try to take thinking about them especially the low-level primitive.
     
  21. Leuthil

    Leuthil

    Joined:
    Jul 26, 2013
    Posts:
    97
    @MelvMay, there was an old issue I had in regards to PolygonCollider2D.SetPath being slower than I expected. I was wondering if any of these updates to 2D physics would improve the performance on this. Specifically the features of low-level collider primitives being exposed, multithreading, and asynchronous PolygonCollider2D triangulation.

    This is the old issue I am referring to:

    https://forum.unity.com/threads/polygoncollider2d-setpath-slow.349368/
     
    Last edited: Nov 15, 2017
  22. Isint90

    Isint90

    Joined:
    Jan 29, 2018
    Posts:
    1
    Last edited: Jan 31, 2018
  23. unityBerserker

    unityBerserker

    Joined:
    Mar 31, 2016
    Posts:
    5
    @MelvMay Hi,
    I see that - Expose low-level collider primitives of circle, edge, polygon & capsule and ability to retrieve from existing Collider 2D components is in development.
    I created methods to visualize geometry queries (also I visualized quaternions and vectors).
    https://github.com/uvivagabond/Visualization-of-physics-in-Unity
    More info in wiki.
    I must improve some of methods for better displaying, refactor some names and add support for future improvements for 2D physics.
    In next few month I plan to describe all physics in unity and add additional methods to visualize.
    Maybe this repository will be helpful for future improvements.
     
  24. emmawatson8855

    emmawatson8855

    Joined:
    Feb 22, 2018
    Posts:
    2
    It's better to see the future improvements for 2D physics
     
  25. sayiliromer

    sayiliromer

    Joined:
    May 30, 2017
    Posts:
    11
    Is there any possibility or planned feature to use 2D physics engine without components ? Like we did on standalone Box2D by pushing shape and rigidbody and listening collision events etc ?

    Somehow like this

    Code (CSharp):
    1. Shape shape = new CircleShape(1f);
    2. Body body = new Body(shape);
    3. body.mass = 1;
    4. body.onCollisionEnter += OnMyBodyCollide;
    5. world.AddBody(body);
    That would be very very good. Because i use MVC pattern in my projects and it is impossible to run physics without instantiating a game object. Which is useless in my case. So i usually use custom physics.
     
  26. Estecka

    Estecka

    Joined:
    Oct 11, 2013
    Posts:
    62
    Hi, regarding Layers and Effectors :

    Effector2D have a pretty unique trait : they let you override an object's collision mask on the fly, whithout having to create a whole new layer. (We have things like
    Physics2D.IgnoreCollision
    for object-to-object and
    Physics2D.IgnoreLayerCollision
    for layer-to-layer, but effectors are the only way to edit layer-to-object collisions.)
    I've actually been using effectors in a project solely for this purpose, not for the fancy effects they provides.
    Will we have something like an effectless effector for this purpose? Or a method to edit layer-to-object collision?
    Any chance we get something similar in 3D ?
     
  27. RodneyFellington

    RodneyFellington

    Joined:
    Oct 9, 2018
    Posts:
    1
  28. andre_unity573

    andre_unity573

    Joined:
    Oct 17, 2018
    Posts:
    34
    Very interesting!