Search Unity

DPhysics Beta - Cross-platform Deterministic Physics engine

Discussion in 'Physics' started by jpthek9, Apr 14, 2015.

?

Should DPhysics be tailored for RTS, TD, and MOBA games?

  1. Yes, throw in pathfinding, local avoidance, and crowd behavior

    61.3%
  2. No, keep it as a true physics engine

    38.7%
  1. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    The first Beta version of DPhysics will be released this weekend! To sum it up, it's a high-performance cross-platform-deterministic fixed-point ass-kicking circle-massing polygon-colliding physics engine.

    If you're interested in joining the Beta team and receiving the release, post your email on this thread or email me at JPtheK9@gmail.com. Also post any bug finds, suggestions, or feature requests here. This physics engine is being built from the ground up so what you want is the most important part!

    Here's a video to show you what you're getting into:


    Happy developing :)
     
    Last edited: Jul 16, 2015
    cl9-2 likes this.
  2. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Here's a demo of crowd behaviors made using DPhysics's event callbacks to whet your appetite for the first Beta release.
     
    Last edited: Apr 16, 2015
  3. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    DPhysics Beta 1.0 has been released! For any bug finds, suggestions, or questions, please email me or post it on this thread and I'll get back to you on it as soon as possible.
     
  4. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Here's what's coming up in the next big update, DPhysics B2.0:
    -[Completed] Drastic math optimizations; simulation speed doubled.
    -[WIP] Lockstep multiplayer demo using DarkRift
    -[WIP] More realistic physics

    Please, if there's anything you'd like added in, changed, etc., let me know! Your input is one of the most important things for DPhysics at this stage. With it, I will keep pushing DPhysics in the right direction.
     
    Last edited: Apr 21, 2015
  5. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I sent DPhysics off to the Asset Store but they haven't responded to me for a while. I've sent out DPhysics 1.1 to everyone on the testing team to not keep you guys waiting.

    1.0 New Features:
    - Multiplayer Demo with 200/400 objects

    1.1 New Features:
    -[Completed] Parenting
    -[Completed] "Newton's Chain" example
    -[WIP] In-scene cached objects
    -[WIP] Better editor integration
    -[WIP][Pro] Multiplayer Replays
     
    Last edited: May 14, 2015
  6. RobertFitzgibbon

    RobertFitzgibbon

    Joined:
    Mar 2, 2015
    Posts:
    32
    Sorry, I just posted on your old thread and then found this one, but I'm definitely interested in testing out all the new features! I'd love to be on the beta team!
     
  7. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Glad you're on the team :)

    It took me a while to get the webplayer demo working but it worked out in the end. Here's the link.
     
  8. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Sorry I haven't been whipping out updates rapidly. I've been working on an iOS game with DPhysics for replays.

    On a sidetone, an interesting idea came to: simulate physics in Update() with a set target framerate. I've implemented it and so far nothing's exploded besides what should be exploding. Simulating physics in Update() would give the advantage of being able to directly get inputs instead of having to use a buffer for FixedUpdate(). Anyways, just a cool thing to try if input is being annoying for you.
     
  9. jharger

    jharger

    Joined:
    Jul 22, 2011
    Posts:
    11
    Hey, are you still doing a beta? I'm developing a very strange game for mobile devices, and I think this sort of thing would be absolutely necessary for multiplayer! :)

    Does DPhysics have similar features to the Unity (2d) physics? Specifically, does it have the ability for moving kinematic bodies to collide with dynamic bodies?

    Thanks!
    This looks pretty sweet
     
  10. toxtronyx

    toxtronyx

    Joined:
    Aug 21, 2014
    Posts:
    114
    Very interesting stuff. Its a pitty that it is all 2D. We made a physics puzzle game in the past and had a non deterministic physic engine in use but with all the disadvantages. How about joints and complex constructions like building complex machines out of different parts like in the incredible machine, or Crazy Machines? Working only 2d could be fine if the appearance of the objects is 3d like in your web player demo. Just a few thoughts :)
     
  11. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    A lot of things are modeled after Unity's physics but some things are different. For example, objects with 0 mass are kinematic and child objects are made part of the parent's physics, as if the parent's collider was expanded. Also, DPhysics is built on the XZ plane for 2.5D games that have 3D models with 2D simulations (i.e. RTS games).

    I haven't explained very well in the documentation about kinematic bodies. With 0 mass, an exception occurs where the object cannot be affected by other objects but other objects are affected by it. The walls in the web player demo have 0 mass so the balls bounce off of them but the walls don't get pushed back by the balls. Velocity is disabled for kinematic bodies but changing their position works fine.

    I've heard that the change from 2D to 3D won't be too hard since a lot of the concepts are similar, but because DPhysics was made for RTS, TD, and MOBA games, I've chosen to make it a 2D physics engine, since a lot of optimizations and compromises can be made for a 2D physics engine. A 3D expansion might happen in the future though, for FPS games and the like.
     
    Last edited: May 18, 2015
  12. jharger

    jharger

    Joined:
    Jul 22, 2011
    Posts:
    11
    Sounds exactly like what I'm looking for. I'll send you an email.
     
  13. toxtronyx

    toxtronyx

    Joined:
    Aug 21, 2014
    Posts:
    114
    Thanks for your fast reply. Still not sure if it works for puzzle game like those I mentioned. Sorry for any kind of stupidity it was a long day ;-)
     
  14. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I haven't played either game, but what you described is possible. Keep in mind that physics objects in DPhysics are thought of as agents so they don't roll or transfer rotational velocity.
     
  15. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I've been thinking, since the games that need deterministic physics the most are RTS, TD, and MOBA games, should I tailor DPhysics for that? DPhysics would no longer be viable for puzzle games but it will have features specially suited for agent crowds.
     
    Last edited: May 18, 2015
  16. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I'm currently working on integrating the replays feature. Should replays be saved in PlayerPrefs or JSON?
     
  17. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    json definitely.
     
  18. KHRZ

    KHRZ

    Joined:
    Mar 2, 2013
    Posts:
    56
    Just chiming in here. Working on an RTS game too, so would be very interested in path finding/local avoidance in an integer math engine. Very exited for the asset store release. Maybe you can modularize the physics / lockstep server / path finding for those who don't want it? Or would they need heavy ingrainment for good performance?
     
  19. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Modularity would be a neat feature but as you suggested, there will be some performance demands from that. To be honest, the main issue is workload. Packing both a physics engine and an RTS engine into a single package would require many things to be coded twice. I too am interested in working on an RTS game and I think that a deterministic 2D physics engine would be most useful for those types of games - but I'll put my efforts into what people will benefit most from.

    Again, sorry for the delay on the replay feature release. Creating a coherent replay system and a demo to go along with it has been more complicated than I expected.

    Note that I also plan to squeeze in collision layers into the upcoming release. After that, all the features I want for the first release will be completed so this will be the last Beta I send out before I start preparing DPhysics for the Asset Store.
     
  20. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I just got notified that DPhysics Evaluation was accepted to the Asset Store (but Pro had some problems with its images). It was sent a while ago and doesn't have all the features I want to put in, but if you missed the last Beta release, you can download it here. Any feedback on the product page and presentation would be very helpful.
     
    Last edited: May 28, 2015
  21. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    193
    Working on an RTS as well, looks like DPhysics is exactly what I've been searchin' for. Gonna keep an eye on this

    Edit: Is it possible to disable certain objects from being pushed around by collision?
     
    Last edited: Jun 7, 2015
  22. TheEvilRabbit

    TheEvilRabbit

    Joined:
    Aug 25, 2014
    Posts:
    26
    Please can you pm me to discuss DPhysics!
     
  23. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    To be honest, I kinda released DPhysics half-baked. Check this link out for the source code to implement it yourself: https://www.dropbox.com/sh/9zuy4lmelfoujm8/AACLCeOQiKajjHc-IAUBMy9ra?dl=0.

    Development on DPhysics has stopped and been shifted to the Lockstep Framework which will cover not only the deterministic physics side of RTS games, but also pathfinding, abilities, and steering. Because of that, everyone should feel free to use the source code of the latest version of DPhysics (linked above).
     
    Crayz likes this.
  24. msmsm

    msmsm

    Joined:
    Feb 1, 2014
    Posts:
    49
    Hi,

    Thanks for making this available. I was wondering, is there a simple way to do raycasts against the Bodys in the scene? I have looked through the code and documentation and can not see an equivalent to Physics2d.raycast and I was just wondering if I had missed something or whether this had been left as an exercise for the reader, so to speak!

    Matt
     
  25. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    No, DPhysics uses quad tree partitioning which is pretty nasty to partition raycasts. You could "hack" it in by attaching a long ray-shaped object for bullet hit detection. Like I said before, DPhysics is kind of half-baked. It best serves simple multiplayer RTS or TD games or as an extendable codebase.
     
  26. msmsm

    msmsm

    Joined:
    Feb 1, 2014
    Posts:
    49
    Thanks for the quick response. I was going to use a raycast to see if I had line of sight between 2 units in the RTS I am messing about with. I could use an object, as you suggested, it just feels like a raycast is the correct thing here. Guess I may need to dust off my old maths books....
     
  27. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    A lot of games actually use influence maps and not physics for things regarding line of sight. Bresenham's algorithm (which would be used anyways for partitions) pretty efficiently casts a ray across a grid.
     
  28. ScriptGeek

    ScriptGeek

    Joined:
    Mar 4, 2011
    Posts:
    45
    I'm trying to figure out how to interact with GameObjects using DPhysics, so I setup a little experiment to try to get force applied to an object within the MonoBehaviour Start method. The object appears on screen, but is uninfluenced by the Body.ApplyForce method call in my script. What could be happening here?

    EDIT: Solved. I figured out from the example code how to get this working. Code provided below.

    The object is a Unity GameObject with the following components attached:
    • Transform
    • MeshFilter
    • MeshRenderer
    • DCollider (Script)
    • Body (Script)
    • ApplyForce (Script)
    The DCollider component has property settings:
    Vertices: Size 0 (empty)
    Is Circle: unchecked
    Radius: 0

    The Body component has property settings:
    Is Trigger: unchecked
    Mass: 1

    This is code for the ApplyForce script component:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using DPhysics;
    4.  
    5. public class ApplyForce : MonoBehaviour
    6. {
    7.     void Start ()
    8.     {
    9.         Body body = GetComponent<Body>();
    10.         Vector2d force = Vector2d.up * 10;
    11.         body.ApplyForce(ref force);
    12.     }
    13. }
    14.  
    Code that works:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using DPhysics;
    4.  
    5. public class ApplyForce : MonoBehaviour
    6. {
    7.     void Start ()
    8.     {
    9.         Body body = GetComponent<Body>();
    10.         Vector2d force = Vector2d.up * 10;
    11.  
    12.         //Initializing the simulation
    13.         Time.fixedDeltaTime = .1f; //Setting our fixed update rate
    14.         DPhysicsManager.SimulationDelta = FInt.Create(.1d); //Syncing DPhysics's simulation rate with Unity's fixed update
    15.         DPhysicsManager.Restitution = FInt.OneF; //Restitution of 1 results in complete conservation of momentum
    16.         DPhysicsManager.CollisionDamp = FInt.ZeroF; //No reason for collision offsets since objects aren't clumped
    17.         DPhysicsManager.Drag = FInt.OneF; //Velocity is completely conserved
    18.        
    19.         body.Initialize(Vector2d.zero);
    20.         body.ApplyVelocity(ref force);
    21.     }
    22.  
    23.  
    24.     void FixedUpdate ()
    25.     {
    26.         DPhysicsManager.Simulate();
    27.     }
    28.  
    29.  
    30.     void Update()
    31.     {
    32.         DPhysicsManager.Visualize();
    33.     }
    34.  
    35. }
    36.  
     
    Last edited: Aug 22, 2015
    jpthek9 likes this.
  29. ScriptGeek

    ScriptGeek

    Joined:
    Mar 4, 2011
    Posts:
    45
    Does kinematics work with this engine? If so how to setup a simple example of connecting two objects together? If not how can an anchor (or pivot point) be placed on an object so that the object rotates about this anchor?

    Edited to be more specific to the situation.
     
    Last edited: Aug 24, 2015
  30. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    No. The physics were developed for RTS games... getting 2 units to push each other away and keep them from occupying the same space at the same time.
     
  31. ScriptGeek

    ScriptGeek

    Joined:
    Mar 4, 2011
    Posts:
    45
    Well, that's too bad. But it looks like I can still use DPhysics for what I need anyhow with some trickery. By parenting the GameObject to another and switching the Body and DCollider components to the parent I can still get it to work. It's not kinematics, but my requirements are simpler. Thanks for your quick response!

    EDIT: I forgot to mention that I reset the Body.Position on the Body component of the parent GameObject every frame to keep the object from moving around.
     
    Last edited: Aug 24, 2015
  32. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Can you repost the source code please? The Dropbox link in this thread no longer works.
     
  33. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Look for Lockstep Framework. It includes a lot of DPhysic's logic and also has a deterministic physics engine, determinism checker, and more.
     
  34. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Hey buddy, are you still developing this asset? It looks so promising. I have rigidbody based controller to be networked and DPhysics seems the only shot.
     
  35. parth20

    parth20

    Joined:
    May 30, 2014
    Posts:
    2
    where I can find this Dphysics and how can I integrate it. actually I am currently working in 8 ball pool game and I am facing proble over network as unity's physics is nondeterminstic every time same input make different result.
     
  36. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    104
    Has this been abandoned? I could really use it.
     
  37. AidanofVT likes this.