- Home /
Terrain Friction - ball on terrain??
Hi all, I'm rather new to Unity, so forgive my stupid question :-) tried to look for an answer on the forum but for some reason I get timeout every time I search so here it is:
I made a terrain with the terrain editor, and I scripted a sphere (with rigidbody) launcher. When I spawn my spheres, they start rolling on the terrain in a very unrealistic way, just as though there was no friction at all from terrain.
At first I thought the solution was to apply a physics material to both my sphere and my terrain, but even with a static and dynamic friction of 1 on both the sphere and terrain, my sphere keeps on rolling and rolling and rolling, never stopping.
So what's the deal? How can I get my terrain to have friction?
I uploaded a small video to illustrate my issue http://www.youtube.com/watch?v=8xqaaP2cHBc
Answer by Fattie · Dec 26, 2012 at 02:44 PM
Fortunately it's probably this simple -- in RIGIDBODY for the sphere, look at drag (AngularDrag can also be useful.)
In your case, the little bastard is ROLLING, so FRICTION DOES NOT APPLY. If you change to a cube, and sort of push it around the terrain (for example, tilt the whole terrain and let it slide), then friction is what you are looking for. (Funnily enough this question just came up, which may be of further interest http://answers.unity3d.com/questions/369066/exactly-how-does-friction-direction-2-work.html - purely FYI, not relevant here. )
In this case, the only thing that will slow down the ball ROLLING is the "drag" paramater.
The "drag" parameter is, funnily enough, one of the most important when doing physics in games, it is critical. Hope it helps.
Hello, you reply:
"I've tried playing with drag, but then it affects my object's air speed, which is an unwanted consequence"
Just to be absolutely clear: you can get EXACTLY the effect you want, using drag, when the ball is rolling.
is this correct? If so, pls tell me the drag figure that gives you the exact result (WHEN ROLLING) that you want.
Now, WHEN YOUR BALL IS AIRBORNE, it sounds like you need a DIFFERENT drag figure. if this is correct, pls again tell me that figure! Cheers...
I'll offer a smart-arse solution while you are deciding on figures. Try this. Set the ANGULAR DRAG to a high value. In fact if you think about it ... when rolling, IT HAS ANGULAR VELOCITY. In some situations - depending on the size of the ball etc - the angular drag will slow it down perfectly! Give it a go... leave drag at zero, and set high angular drag.
Try this, in a blank project create a plane and a sphere. Lean the sphere down a little to the right, put the sphere a bit above the left side of the plane, in the sphere rigidbody turn on gravity. Click play it will fall to the plane, and roll to your right.
Hit stop. Add a ConstantForce to the sphere. Hit Play again. Now fiddle with the two values the arows are pointing to:
(Note for instance that if you torque it REALLY hard, you'll see it "spinning on the spot" like a steam engine getting going and the wheel slipping. Note that GENERALLY the plain force is what you want for a cheap solution but torque can be better sometimes.)
The big problem you face - you actually want it to behave differently when it is on the terrain versus in the air.
That's the fundamental problem here - you'll need a script with a line of code in Update() to determine if it is grounded. If it is, turn o the air-drag ... if not, turn off the air-drag.
Alternately, if it is grounded, get the current velocity and apply some force against that velocity. (And, don't do that while airborne.)
So a problem is, how to know if you're grounded. Is the terrain perfectly flat? then - just look at the height (pos.y) of your object. Even if it is only "slightly bumpy" you could still use that as a solution. Beyond that one could raycast to get the height above the terrain everytime or search on here for other ideas on seeing if you are grounded.
So essentially you are making your own drag (a force that goes i the opposite direction to current velocity) when you are grounded, but you want different behaviour when airborne.
Or, if the drag feature does it for you, just turn that on or off depending on whether it is airborne or not.
Ok I get it, since my collider is a sphere (tried with a capsule as well) the contact surface with the terrain is too small for friction to apply. I've tried playing with drag, but then it affects my object's air speed, which is an unwanted consequence. A cube collider would be unrealistic, what I would probably need is a polyhedric shape, like a 12-sided dice or something. Where can I find this? I already red through the direction2 post. Very interesting, but not of application in this case.
One point: "the contact surface with the terrain is too small for friction to apply"
Just to be absolutely clear: sliding friction COULD ALSO apply here in PhysX. (Although it is not applying, I can tell your ball is rolling.)
Furthermore, don't forget we're talking about "what happens in PhysX" - this has no relationship at all to actually engineering for ball bearings or the like.
I will answer your further question now ...
Ok thank you for all this. I'll have played around a bit.
I believe the thing about drag that fails to make things look realistic is that it never stops my object from moving as long as there's a slope on the terrain, no matter how high I set the drag.
Angular drag does seem to work better than normal drag indeed. I need to do some more reading to understand the underlying subtleties.
I guess I could indeed try things out with the grounded check, in this present case it's a bit overkill since it's just a projectile, and I could technically throw a lot of them. I'm just working these things out as a tutorial but if I ever need to get deeper into this for a real project I might very well explore that path.
For now, I'll just go by your very true statement that this is not a ball bearings simulator
Your answer
Follow this Question
Related Questions
Angular Friction 0 Answers
Calculating Sphere vs. Plane Friction 1 Answer
How to make moving objects stack, without sliding over each other? 0 Answers
Calculating required force for pushing a body to a desired position at once 0 Answers
What is the appropriate value of Friction Direction 2? 1 Answer