I need ways to improve Physics Collisions

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().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

2 Likes

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.

1 Like

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.

1 Like

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.

1 Like

@Ashanex : Did you have time to look into my question above about some reproduction steps?

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!

1 Like

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.

1 Like

I did this via raycasting and capsule sweep methods and made some manual reflective approaches for missed passes.Unity doesn’t have accurate collision detection for fast-moving dynamic objects.

Hello @Ashanex ,
this is really amazing! Did you manage to fix those issues?
Did Havok help you in any way?

Hey! We didn’t use Havok, in fact the physics of Havok felt pretty off. We hired a physics programmer that created a full on physics system for Unity designed to be accurate in VR. We are pretty happy with the results and we keep working on it to this day. Sorry to not be able to give a more satisfying answer!

2 Likes

A complete physic system? Wow that’s a huge work! Which are the main differences respect of standard physic engine? Just the being fully deterministic?

It’s way more precise, it updates nearly 100.000 times per second. And because we have the source code it allows us to precisely tune it. It’s very focused on ball physics. You can check out our game in the Meta Store on a Meta Quest 2 or 3, it’s in public early access! Look for Padel VR Game / Training :slight_smile:

2 Likes

Do you really need so many updates per seconds? Usually a ball in a racket game doesn’t go so fast…