1
votes

So i am making a simple Golf game, when trying to replicate the balls movement i have noticed that on slopes the ball functions very oddly, it either never stops or stops too quickly and when travelling down slopes will reach a very slow terminal velocity quickly (ie it stops accelerating down slopes). So it either doesnt deaccelerate enough going up a slope or accelerates too slowly going down a slope.

I have been messing about with angular and static Friction of both the ball and the surface to see if that changes it at all and i have also been changing the friction combine of the surface and the ball to see if that makes any difference and so far haven't had any luck.

Is this a common issue with Unity because i haven't been able to find any other questions about it on here. If anyone could give me some advice on how to have my ball not roll forever but still accelerate when going down a slope that would be great

EDIT: The ball has a rigidbody with continous collision, then the course uses a mesh collider. Both however have attached physics materials

The ball is currently just a basic sphere from unity using a sphere collider, i havent tried changing the rigidbody about much yet other than mass. When the ball is hit i addforce to it, the slopes are an asset i have purchased that are perfectly smooth.

RigidBody Slope Physics Flat Physics Ball Physics

1
A sphere collider is just a point collider, so it's likely your ball will not actually spin, is that correct ?Fattie
I believe it does because when i attach the camera to it, the camera starts orbiting the ballReece Hewitson
I think that would be a whole other question. If it's a point collider, there's no reason at all the object would "tumble", spin on it's axis. I suggest, replace the texture of the ball with any other texture at all, and, you will get more info about whether it is turning! Again this is a whole other topic, and you (can and should) ask more questions about tumbling objects and ball physics! Again, GameDev may be more useful.Fattie
Not worthy of a whole answer but suggest you check out: "WheelColliders". Normally these are used for vehicles, but I think it might be suited to this case too.Glurth

1 Answers

2
votes

Rolling object physics are indeed difficult in game engines.

As I mention in the comment for such questions it's necessary to know (a) what sort of collider and (b) what sort of object it is, since there are at least 4 major approaches to this problem.

But in general you usually have to manually add the "slowing down" function, in a sense representing air resistance.

For a moment set aside the collider choices, and imagine in the abstract you have a ball rolling along a flat plane. You've somehow started it moving at 2 m/s say.

There's really no reason at all it will stop rolling or slow down. Why would it? There's no air resistance in physX and what you "want" it to do in the game engine physics is keep rolling.

Thus what you do is add a script that, essentially, "slows it down a little" every frame. In pseudocode, something like

velocity = 0.99 * velocity

Note however that alternately, to "manually slow it down", you may have to simply add force to it.

The trick is you do that in the opposite direction to movement

yourBalls.addForce( v.normalized * -1 * some small force )

(It's easy to think of that as basically "air resistance")

You usually also, simply, just add a top speed. In this way on downslopes it won't just get "infinitely fast"

if (v.magnitude > 3.0) v = v.normalized * 3.0

That's basically how you make objects roll around on hilly surfaces.

Note that you basically should not fool with the friction settings in anyway, it's really not relevant in most cases.

Unfortunately there is a vast amount of detail but, I feel your question is more asking for the "basic principles" - and there they are!

Tip: it could be this question is more suited to the gameDev site, where "techniques" of game physics are QA'd.