Reece Hewitson
Reece Hewitson

Reputation: 101

Unity ball friction either too much or not enough

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

Upvotes: 1

Views: 3876

Answers (1)

Fattie
Fattie

Reputation: 12641

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.

Upvotes: 3

Related Questions