- Home /
How to prevent a sphere collider from rolling for prolonged time
I'm working on a golf game and I'm having some problems with the ball rolling for prolonged periods of time. I've tried adjusting the settings under the rigid body as well as the values for the physics material that it uses. However, the ball still seems to roll for prolonged periods of time no matter what I do. The only difference is, the speed at which it rolls. Although cranking the angular drag up seems to reduce the rolling speed, it still continues to roll for long periods of time.
Any ideas as to how I can address this issue? Would I be better off tweaking the rigid body settings, or tweaking the physics material settings? I'm sure it will take a bit of time to customize it for our purposes, but if somebody could point me in the right direction, it would be much appreciated! Thank you.
@holman8er, what did you finally decide to do? I'm trying to simulate a golf ball rolling on a putting green and I'm seeing the same behavior; the ball slows down, but never stops rolling completely. The only thing I've tried that actually stops the ball is to increase both drag and angularDrag each time OnCollisionStay is called, but that seems wrong. Thanks.
Answer by aldonaletto · Jan 03, 2012 at 11:39 PM
You could increase the rigidbody.drag as well, but this could kill the velocity while in the air. I think you could try to reduce the velocity and angularVelocity in OnCollisionStay, thus it would fly freely but loose energy quickly when rolling on the ground:
var velDamp: float = 0.01; var aVelDamp: float = 0.01;
function OnCollisionStay(){ rigidbody.velocity = 1 - velDamp; rigidbody.angularVelocity = 1 - aVelDamp; }
Another alternative could be to increase the drag and angularDrag in OnCollisionEnter, thus the behaviour in the air would not be affected:
var dragInc: float = 0.2; var aDragInc: float = 0.2;
function OnCollisionEnter(){ rigidbody.drag = 1 + dragInc; rigidbody.angularDrag = 1 + aDragInc; }
Thanks Aldon, we're definiteley on the same page here. I have in fact tried increasing the angular drag OnTriggerEnter, and it seemed to work better than normal. However, when the ball is on a slope in the terrain, it continues to roll, just not as fast. This is especially a problem when the ball goes into a sand trap and lands on a slope. It doesn't matter if that slope is steep, the ball should still stick into the sand and only roll for a very brief period of time (if it all). But ins$$anonymous$$d, it rolls down the slope extremley slowly for an extended period of time.
You should increase rigidbody.drag as well: it opposes to the movement, stopping the ball early. You could also try to use OnCollisionStay ins$$anonymous$$d of OnCollisionEnter: notice that the drag factors are increased exponentially each time the event occurs.
Important note: don't let rigidbody.drag = 0, since zero raised to any exponent will still be zero. Set rigidbody.drag to a small value, 0.1 or lower, and use OnCollisionStay as I suggested in my last comment: I tried it, and the ball stopped like in a tar pit with these settings. You can even change the dragInc factor depending on the material the ball collided with - this 0.2 value is good for sand, and maybe 0.05 could be better for grass, for instance.
Your answer
Follow this Question
Related Questions
How to have a sphere roll/be affected by friction 0 Answers
rolling ball movement on different axis 0 Answers
Activate physics when animation ends 0 Answers
Rotating sphere with rigidbody attached 1 Answer
Smooth Player Ball Rolling 1 Answer