🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Setup golf ball physics

Started by
5 comments, last by frob 6 years, 2 months ago

I am developing a simple Golf game (using Scenekit) as shown in the below image.

5ad41cb9ab5e2_ScreenShot2018-04-12at5_11_00PM.png.a36042c201214d9abe592d2c17eb8ea7.png

I am facing below issues:

 1. Even if I apply small amount of force, the ball continuous move along the grass? Grass friction is not stopping the ball.
 2. Sometimes, the ball speed is increased after colliding with the walls instead the ball speed should decreased after collision with the walls. The walls are having box collider.
 3. Sometimes, the ball reverses its direction after colliding with walls.

Code:

Physics properties of the ball:


 ball.physicsBody.affectedByGravity = true;
 ball.physicsBody.mass = 0.0450;
 ball.physicsBody.restitution = 0.8;
 ball.physicsBody.friction = 0.3;
 ball.physicsBody.allowsResting = true;

Physics properties of the grass:


golf.physicsBody.friction = 0.8;

Physics properties of the walls:


 leftWall.physicsBody.friction = 0;
 leftWall.physicsBody.restitution = 0.8;

I have set the physics world gravity value to -9.8.

I am looking for suggestions to fix the above listed issue. Thank you.

 

Advertisement

If your physics system supports rolling resistance, it belongs there. Unfortunately it isn't often supported. 

If it doesn't support rolling resistance, it is probably something you'll need to simulate. 

 

The easy/lazy form is to scale your velocities slightly while rolling, such as every time step multiplying by 0.99f or whatever works for your game.  You'll need to get both linear and rotational velocities if you go that route. 

A more complex method is to figure out the rolling resistance. The coefficient of rolling resistance is something you can calculate or look up online, it will likely be something around 0.01 or so. Compute the magnitude of the force (mass * downward gravity or forces * rolling resistance coefficient), then apply that force in the negative velocity directions clamped at the force needed to stop the object.

8 hours ago, frob said:

If your physics system supports rolling resistance, it belongs there. Unfortunately it isn't often supported. 

If it doesn't support rolling resistance, it is probably something you'll need to simulate. 

 

The easy/lazy form is to scale your velocities slightly while rolling, such as every time step multiplying by 0.99f or whatever works for your game.  You'll need to get both linear and rotational velocities if you go that route. 

A more complex method is to figure out the rolling resistance. The coefficient of rolling resistance is something you can calculate or look up online, it will likely be something around 0.01 or so. Compute the magnitude of the force (mass * downward gravity or forces * rolling resistance coefficient), then apply that force in the negative velocity directions clamped at the force needed to stop the object.

Thank you for the reply. Yes, Scenekit has the rolling resistance property. Even if I increase the rolling friction of the ball to 1.0, the ball continues to move along the grass surface.

Changing velocities at each time step will be same as linear damping and angular damping, right? I have already tried changing those values without success.

 

On 4/17/2018 at 3:05 AM, frob said:

The easy/lazy form is to scale your velocities slightly while rolling, such as every time step multiplying by 0.99f or whatever works for your game.  You'll need to get both linear and rotational velocities if you go that route.

I tried this suggestion but somehow this approach is not working when the ball size is too small. I am testing the code with ball size of 0.8cm. Is there a possibility that physics engine won't work properly with such small objects?

I am not familiar with SceneKit physics but for simulating such small objects and forces you generally cannot use out of the box simulation settings and will need to adjust them. You can try to find if SceneKit has similar settings to that of Unity3D: https://docs.unity3d.com/Manual/class-PhysicsManager.html

9 hours ago, nims92 said:

Is there a possibility that physics engine won't work properly with such small objects?

It's always a possibility. More likely it has to do with masses and other physics properties, though.  Typically there are physics values set to bad values. Getting values that are suitable for the simulation and close to real-world reactions can take time to get right.

You mention it supports rolling resistance. That's based on the mass of the object, its velocity, and the coefficient between two surfaces. Get any one of them wrong and the function won't work as expected.

This topic is closed to new replies.

Advertisement