I was tossing around ideas on games (where I could create my own art assets) while learning UE4 and though of billiards. However in my first attempts at testing collisions the spheres didn’t seem to be colliding in a way I’d expect of billiards. It may just be my settings and limited understanding of the physics systems. But I though I would ask if a playable billiards game would require something more precise than the built in physics features.
One very noticeable issue is when I press simulate on the image below the balls (which have gravity enabled) will just sometimes fall right through a brush, or sometimes they will collide and bounce off. It happens randomly each time I simulate. What settings do i need to tweak to ensure the ball (57mm in diameter) won’t pass through?
Edit: I’ve done some experimenting. I created a new empty map, dragged a box, then placed six Shape_Spheres 100 units apart above it (see image below). I set each sphere to simulate physics and scaled each to be half the size of the previous sphere. When I run simulate, the two smaller spheres which are 6.25 and 3.125 world units in diameter will occasionally pass through the box while the larger spheres seem to never pass through. (It’s fairly random, it may take 10 times or more running simulate to see them pass through)
Is this a bug or is it a limitation of the physics system? If it’s a limitation what are the edge cases to avoid?
As a workaround I figure I could modify the world settings: “World to Meters” to have 57mm spheres which larger world unit diameters. If I do this what else would I need to alter? For example would I need to adjust Global Gravity Z or does it automatically adjust based on the World to Meters value?
PhysX is certainly good enough to create a playable billiards game, but like all other real time physics engines it’s not perfect so just keep that in mind.
The engine itself does not care what units you work in as long as everything is scaled properly with your units (gravity and other foces for example). Small objects are known to pass through other objects if they travel too fast. To combat this you can enable ‘Continous Collision Detection’ (CCD) for your spheres.
Also try to avoid having planes as collision objects. Give them some depth, or an invisible box collision component.
I know in UE3 you could also change the steps the physics engine takes to solve collision for greater precision, I would assume there’s a setting for this somewhere in UE4 as well (World settings probably :)).
One last thing to remember is that physics games have a sweetspot where they behave like you want them to, and anything outside of that causes catastrophic behavior. So even though everything is set up right except a few tweaks to mass and forces it can look like it’s completely broken.
For small, fast-moving physics objects you probably want to enable the ‘Use CCD’ option (in the advanced section under Collision). This tells the physics engine to do some extra work to prevent penetration using ‘continuous collision detection’. Do note though that a general purpose physics engine may not give you quite enough control to make a billiards game, but it should certainly give you a good start. I imagine you may get some problems with high-velocity elastic collisions from bumpers.
Thanks Dieselhead. The CCD did solve the passing through issue. I am having one final issue you might know about. When I apply a force (once) to my sphere it won’t come to a full stop, no matter I set friction or linear or angular damping values too. They can slow it down but it will keep going.
Here’s the setup:
create an empty level in a project with the default content
create a default landscape (so you have a practically infinite plane)
drop a Shape_Sphere on to the landscape.
Open the level blueprint and on Event Begin Play, Add Force of 500000.00 in the X axis to the Shape_Sphere.
Press esc to make sure you have nothing selected in the editor and press simulate. (Having something selected will halt it if you click during simulate)
The ball will move forward a bit and it will slow down but it will never stop completely.
I’m only guessing but there’s usually a cap value for when to put the objects to sleep. This page mentions something called Sleep Family which sounds like it could be what you’re looking for. Put the object to sleep if it’s moving at a very slow velocity for example.
I looked at this a bit and it appears that the linear and angular damping values reduce the actor velocity to a diminishing effect as the object reaches a low velocity. This results in the halving problem in which the object never really reaches a zero velocity. Changing the sleep family values has little to no affect. The only way I found to stop the object was to evaluate the velocity and when it reached this low threshold to lerp to a zero velocity. This does seem very hack-sh. See How do you apply friction or drag to the Physics Ball? - World Creation - Epic Developer Community Forums.
Did anyone solve this?
Spend whole day trying to get normal ball physics without any luck. The ball always keeps on rolling by itself on a flat surface almost to no end.
Brilliant! This is what I’ve been looking for! I have small, fast moving projectiles in my game that must do physics when they hit walls, and I have had about 1/3 go through walls at various angles and distances. Turning on CCD completely fixed this issue! Thank you! Do you know if this affects performance in a significant way?