Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

2D Physics : Manual Simulation, Simulation Groups & Multiple Worlds

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

  1. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,413
    I just don't follow what you're saying and it seems to be going in circles. I also have no idea what you mean when you say "nothing goes wrong".

    If Time.deltaTime and Time.fixedDeltaTimeare identical then it'll enter the loop each and every time only once as it checks >=.

    Why not just try this yourself rather than trying to convince me this doesn't work. Also, for the final time; please post on another thread. You've effectively took over this thread for your own purposes.

    Thanks.
     
  2. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    696
    Why don't I try it?

    LOVE TO!!!

    But where/how do I set fixedDeltaTime independent of the cycle rate of FixedUpdate() ?

    They seem to be the same thing, but without control of which is first. It seems impossible to know if the FixedUpdate is called before the manual simulation, or after it.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,413
    All this information I have provided to you already in the links above showing you how to set the time and what the order is for the MonoBehaviour callbacks etc.
     
  4. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    308
    Going back to the original topic of this – I'd be very interested in multiple 2d physics worlds.

    In a game we're working on, we're using cavalier perspective. There is a ground plane at which we look from a 45° angle, and there are vertical planes that are aligned to the camera. We use 2d physics for the ground plane. So circles on the ground turn into ellipses etc. Sprites "standing" on the ground are rendered completely flat because they are aligned to the camera (like billboards, but they can still be rotated on the vertical axis).

    There are some scenes, in which we would like to use 2d physics on some of these vertical "sprite-planes" in addition to the normal ground physics. Right now that's very complicated to do, the only easy way is to either use ground physics or sprite-plane-physics for one of these sprites. Or we could simulate it somewhere on the ground plane and then project it to the visible plane, but that seems very cumbersome. For this it would be very useful to have small 2d physics worlds, one for each 2d object that uses physics in local space.

    Is that a use case that would be supported with your approach of having multiple worlds?
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,413
    This feature will be going into 2018.3 and is pretty much complete already. Your scenario will be possible with the feature.
     
  6. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    308
    Great to hear, thanks!
     
  7. jollyblade

    jollyblade

    Joined:
    Mar 20, 2014
    Posts:
    4
    Hey Guys,

    It's a really good thread, but I still have some questions about how to organise some things, and why things are so as described here.

    First of all, why is the Simulate called in the Update?
    Why is it not just in the FixedUpdate()? Am I missing some info?

    Like this:
    void FixedUpdate(){
    // apply input, and then
    Physics2D.Simulate(fixedTimeStep);
    // do anything else with the results
    }

    I need this to be able to re apply input, for local prediction, from an earlier state.

    What I do:

    I set the rigidBody properties to the latest available from the server, then I take my input from my buffer, and reapply the remaining. However it does not really work, and I don't understand why.


    What I do:

    void FixedUpdate ()
    {

    reset each networked rigidbody to acked state from server
    // everything else is kinematik atm

    for each input > acked input
    {
    apply Input; // add forces, torque, etc
    simulate(fixedDeltaTime); // do a simulation step for the given input
    }
    }

    But this unfortunately does not work, and I don't really understand why. It seems that either the reset breaks something, or doing multiple simulate calls in one fixed update is basically bad.

    If there are 3 - 5 not acked inputs in the queue, they all have to re simulated and applied onto the last result from the server, meaning that in one fixed frame all the inputs needs to be simulated.

    Or not? what do you think? How is it done properly?

    Thank you very much.
     
  8. chesiq

    chesiq

    Joined:
    Apr 25, 2015
    Posts:
    2
    Hi,
    Thank you for creating this thread!

    I'm currently developing a game a lot like Heat Signature.
    It's in 2D, the view is top down, you are able to control a char that is able to walk around, build and fly spaceships.

    The solution I'm using is a hack ( parenting empty object with player child(with a rigid body) to the ship with a rigid body).

    The problem I'm having is low max usable speed of ships. I can walk on spaceships that are slower than 15 - 20m\s (unity meter per second) and if set higher - player starts to hit lagging behind walls and is able to glitch through the ship walls.

    I need to be able to walk on fast moving ships - like in Heat Signature; as well as use projectile weapons inside fast-moving ships.

    Is there a current possible solution? Maybe making physics deterministic so that walls do not lag behind their visual representations by locking fixed update to the framerate?

    From what I was able to find out games like Star Citizen use multiple physics simulations, I wonder when will be seeing this feature? And if so, will it solve my problems?

    I read about different cheat like approaches like making ships stationary and only moving the world around, but then you are fighting other ships that also have players on them... so I don't want to try out other solutions that I will regret further when implementing multiplayer.

    Thank you in advance.
     
  9. tiltfox

    tiltfox

    Joined:
    Apr 18, 2016
    Posts:
    11
    This is exactly the problem I'm facing. Basically at the moment, unless I've missed something, the only option is to create your own collision solver using casts or overlaps, which is harder than it seemed given the data available from those casts or overlaps. Doing this, you can call your move method to process input whenever you like.

    However, making it behave in many conditions (circle character controller moving into a small space between two boxes, or similar) is hard to solve in an efficient way. I've been researching Speculative Contacts to try to build something that works but it's difficult to shove that type of system into Unity. If anyone has information on that, I'd love to see it.

    The 3D character controller component does this, i think. At least it works in the same way. It can be used in place at the moment, but that means not using 2D colliders which is annoying.

    I've been battling this for a long time now, each time I try to make a better system but it never quite gets there. I would absolutely love some specific information on if it's currently possible to implement client side prediction using unity physics in some way (simulating multiple inputs in a single frame).

    Hopefully what I read above is that you could either put all currently moving bodies in a seperate world and simulate thoseton demand or something, coming in 2018.3. Still, I hope it's possible to simulate multiple times within a single frame (even just one single collider) .

    Is there any information on whether that will be possible in the near future?
     
  10. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    280
    @MelvMay
    Will the simulation groups be included in Unity 2018.3?

    I'm working on netcode and am trying to simulate each individual player Rigidbody2d one at a time....
    Currently I'm setting all other player Rigidbody2d's to "isKinematic" and then simulating physics just for that player and then moving on to the next player.

    Is this an appropriate way to simulate only specific Rigidbody2d's at a time?
    I'm running into an issue where the physics simulation seems to run 2x as fast once I have 2 players in the game, so I'm assuming somehow I'm running the physics step 2x as much as needed. For that reason I'm asking about physics groups as I think it'd help me out!

    Thanks
     
    Deeeds likes this.
  11. wongagame

    wongagame

    Joined:
    May 17, 2018
    Posts:
    2
    HI

    my one query i am develop flip poker card animation. i'm used fliping book page project.
    i'm develop poker card animation but no idea so plz help me.
    i'm create fore card animation but card drag and other three card not proper working.

    – reference pokerrr 2 card show animation
    – reference link :


    Plz help me.

    Thank You !!