I’m making a game similar to a pool game.
That means I have a board with balls that collide with each other and with the board.
The physics Unity implements is perfect for the game, it even has drag and angular drag which makes the simulation quite real.
The problems is that when I apply a considered amount of power to the ball, on the next frame, it is already beyond the table and the physics don’t apply, the ball simply passes through the walls.
After looking up a little on the internet I found the DontGoThroughThings script and other tips about collisions, but none of them worked, because the ball simply goes too fast for the physics to handle.
I don’t think it’s smart to recreate all the physics Unity uses just because Unity can’t handle high speed objects.
I’m blind here on this topic… Don’t know what to do…
Is there a way to use Unity physics to work on high speed objects?
Is there a game which has this kind of physics and the source is opened?
Try setting the rigodbody’s collision detection mode to continuous.
Some additional info here: Unity - Manual: Rigidbody component reference
In your case i would simply recommend to increase the physics framerate (lower the fixedTimeStep in Time settings). The problem is when you want very fast but accurate physics you need a high sample rate or you will miss “something”. However a high physics framerate might be too much for your PC / device.
Unfortunately Unity doesn’t allow to manually drive the physics system. That way you could precalculate some frames by using an initial delay. Something like that could be faked by having a duplicate of your pool table off screen and simulate the physics there. During simulation you could record the positions / rotations and replay them on the visual table without physics, but that’s not easy to get it smooth.
Just came across this and thought i would put in my 2 cents for future generations…
Firstly make sure you are applying force to the rigidbody and not just altering the transform (obvious for some but everyone makes this mistake at first!)
//put this code on the ball you want to move
Rigidbody ball_rb = GetComponent<Rigidbody>();
Vector3 direction = pool_cue.transform.forward; //normalized value to multiply by speed value
float speed = 5f; //adjust this to suit your needs
ball_rb.AddForce(direction * speed, ForceMode.Impulse); //this should to the trick!
//ForceMode from Unity docs
//Force Add a continuous force to the rigidbody, using its mass.
//Acceleration Add a continuous acceleration to the rigidbody, ignoring its mass.
//Impulse Add an instant force impulse to the rigidbody, using its mass.
//VelocityChange Add an instant velocity change to the rigidbody, ignoring its mass.
This does not fully solve the problem yet but its a step in the right direction. Next, widen your colliders on your table walls, make sure they are wide enough so the balls cant slip past them in between frames.
In Edit → Project Settings → Physics you can adjust default solver iterations for more accurate physics (use with care, can be processor-heavy)
I have seen many people reference to decreasing the fixed timestep in Edit → Project Settings → Time, but all this does for me is slow the game down. Perhaps it will work for you.
If your balls are still not moving to your liking, try reducing the drag, angular drag and weight on the balls’ rigibodies. Apply a bouncier physics material with less friction to the balls’ colliders.
Hope this helps!