Search Unity

Feature Request I need ways to improve Physics Collisions

Discussion in 'Physics for ECS' started by Ashanex, May 11, 2023.

  1. Ashanex

    Ashanex

    Joined:
    May 2, 2019
    Posts:
    27
    Hi!

    I'm developing a Tennis(Actually it's Padel) game for VR (Oculus/Meta Quest 2), and I have a pretty solid base, but I'm still having some issues when the racquet collides with the ball.

    This video shows what we are working on:


    List of problems:

    1. The ball intersects with the racquet for a couple of frames on impact.
    2. The ball sometimes (1 in 15 hits) flies away upon being hit in an unrealistic matter.
    3. The ball is hard to push when moving the racquet linearly, but very easy when moving the racquet in an angular movement. Changing the racquet bounciness does not really fix the issue.
    4. The bounce ball direction is sometimes inconsistent. Both in direction and in power.

    I have the timestep set to match the display's framerate: 90hz / 1/90 timestep.
    I'm using this command to do it:
    World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<FixedStepSimulationSystemGroup>().Timestep = 1f/90f;

    The racquet is set to Kinematic and the Ball to Dynamic.

    I've tried multiple approaches to make the racquet follow the hand. The best approach I found is to make the racquet follow the hand by changing its angular and linear velocity every frame.

    I've set the Physics Step component to have the Physics Solver set to 20.

    If anyone has any ideas on how I can fix this issues I would be very glad.

    Thanks for your time!

    Alfonso D.

    @daniel-holz
     
    daniel-holz likes this.
  2. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    277
    Hi @Ashanex. Thanks for reporting these issues.
    Is there any way you would be able to reproduce these issues in a smaller test project, potentially with a kinematically moved paddle, maybe via playback of some recorded paddle positions from hands on tests you are doing?

    I can see how there is some tuning required in order to get the simulation to respond well in most if not all conditions, specifically due to the contact interactions between the dynamic ball and the kinematic paddle.

    Without some reproduction steps and an environment in which one can step by step simulate deterministically through the problematic cases, enable the physics debug visualizations (e.g., the Physics Debug Display) to analyze the issue and then try different parameters to see how the situation could be improved, it would be rather difficult to systematically converge to a good solution.
     
    Ashanex likes this.
  3. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Wow, this looks and sounds amazing!

    Honest question, what benefits do you get in this from ECS? Seems like there's literally 3 dynamic objects and only 2 of them can ever collide.
     
    Ashanex likes this.
  4. Ashanex

    Ashanex

    Joined:
    May 2, 2019
    Posts:
    27
    Unity Physics has extra features like ball spin taking effect on the ground and changing direction upon collision.
    Also it's more consistent when colliding with vr hands.
     
    daniel-holz likes this.
  5. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    277
  6. aducceschi

    aducceschi

    Joined:
    Feb 9, 2022
    Posts:
    39
    Hi Daniel! (I'm Ashanex with a different account).

    Thanks for your interest, unfortunately I have not had enough time to get around to do this. Also after speaking with another physics programmer it seems that we need a different physics approach entirely and he's going to program for us a physics system that works on top of the standard Unity physics that is fully deterministic in terms of collisions. Because (at least according to him) Unity physics are designed for a more general approach and don't handle collisions in a 100% accurate way and this can lead to a lot of object penetration, inconsistency and even not colliding at all if an object moves fast enough.

    It would be cool if Unity standard or ECS physics could have a checkmark that said (If you toggle this Physics will be 100% accurate but it will have a huge performance impact).
    Or maybe in the ECS Physics Step component there could be a third physics option:
    1. Unity Physics.
    2. Havok Physics.
    3. Unity Accurate Physics.

    Not having accurate collisions makes all Ball Sports games require a full physics rewrite.

    Also the engine has no Magnus Effect or Ball Squishing.

    Thanks for your time!
     
    daniel-holz likes this.
  7. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    277
    I would agree that in your specific case where the physical interactions are limited to a single ball hitting surfaces and rebounding, writing a specific solution is a viable and safe option. Let us know if you need any insights on aspects of modeling that.

    For one, it would likely make sense to use shape casts or ray casts from Unity Physics here to get a very detailed understanding on when specifically the fast moving objects (the paddles) would be hit. Modeling then only the effect of the paddle / ball collision and letting the engine take over after this event again could be a good way to build on top of Unity Physics.
    Have a look at our PhysicsSamples project on GitHub for how to modify the physics behavior. It is all very customizable.
     
    Ashanex likes this.