Why does my ball bounce like this? (high hit velocity gives unexpected results)

Hello everyone

I have a minigolf game, when I hit the ball hard at the wall in the pic, the bounce direction equals the black arrow (it doesn’t feel right), if I hit the ball with less force the ball bounces and follows the red arrow as I expect. Is there some setting that would make it follow the red arrow more consistently? I’ve tried turning on sub-stepping and I also applied both the wall and the ball a physical material with high restitution values but it still happens.

UE4.26

Thank you for any input.

You can’t make a physics based game without… you know… physics?

The engine’s physics stuff - or stuff they deal to their users as something resembling a physics engine, called Chaos - isn’t going to get you (or anyone) anywhere.

You can ditch unreal, which is probably the safest thing to do given the state its in - or you can waste a week or so to build a custom branch using PhysX.

Even with Physx you will get issues.

Again, if you want accurate you need to make the mathematical models yourself.
And using doubles in c++ I may add, for even that is very low accuracy when it comes to physics.

Suppose you are “ok” with knowing that the ball will glitch out and take paths you would have never expected just because you are using Unreal…
Then at the very least you need to enable substepping to get some better accuracy and prevent some issues.

You will also need to make all your meshes have a collision wich is at a minimum the size of the moving object * the object’s maximum speed - OR, the object will just clip through things by not colliding.

“You can ditch unreal, which is probably the safest thing to do given the state its in.”
haha I’ve already released the game on steam.

I’ve figured it out anyway. I paused the sim and looked at it frame by frame, with higher velocities the ball ends up tunnelling into the face and on the next frame it ‘corrects’ the tunnelling by basically using the face normal to determine the new velocity. I’ve ended up detecting hits and getting the reflection vector (direction = ball velocity in the last frame, and surface normal = hit.normal), then lerping that reflection vector with the balls velocity last frame and setting the linear physics velocity to that, to get a better result. I no longer get a bounce that feels wrong. I was thinking of switching to a projectile pawn and still might (i assume that’s more deterministic) but this seems to be okay for now.

Here’s what has helped me if anyone is interested.

In the tick function

ballVelo = ballMeshComponent->GetPhysicsLinearVelocity();

In the OnComponentHit function

FVector newVelo = FMath::Lerp(UKismetMathLibrary::GetReflectionVector(ballVelo, Hit.Normal), ballVelo, 0.65f);
ballMeshComponent->SetPhysicsLinearVelocity(newVelo);

Thanks for the input :slight_smile:

So long as its used like a projectile it is much better. When you aet it up to simulate like you would a cannon ball for instance, then it reverts back to the same physics.

Im sure that the math you have running now is more accurate than what Epic did with Chaos :laughing:

It must be made by the type of people that claim 1/0 is 0, or that 2x2 is 24… there is just no other explanation for the results you get with it…

Either way, do consider just building from source with PhysX.
It’s slightly better, particularly performance wise if you need thousends of mesh parts simulating…