- Home /
Cylinders running downhill. Gravity is not enough.
I have a curved ground (model) in my scene working as a hill race track. I have added several cylinders and applied rigid bodies to make them move (roll) down the track. What is the best way to get the cylinders to move the way I want them to move? As it is right now, the cylinders are moving to slow. I want them to speed up when moving down the hill. How can I achieve this?
My solution right now:
function Start()
{
rigidbody.AddTorque(0, 0, 200 * direction);
}
Answer by Goody! · Jan 12, 2011 at 08:26 PM
I like rockets! (ConstantForce) Woosh! Just make sure to angle them correctly so as to not shoot your barrels off into space. :)
Link --> ConstantForce
That seems more like a workaround than a solution (and in any case, it doesn't really correlate with the behavior the OP described).
This might work well. I used rigidbody.AddTorque(0, 0, 100 * direction); in the Start function but your solution is even better.
The impression I got was that you wanted the cylinders to roll down the hill due to gravity in a realistic fashion, in which case applying a linear force (or even a torque) would be a bit of a workaround. But, if it looks right to you and gives you the results you're after, that's probably all that matters.
Constant forces are pretty easy to do if you want to try it out to see if it does what you want. Select your barrel in the Scene View then all a constant force to it via Component/Physics/ConstantForce. Then just fiddle with the variables to see if it'll do what you want. Have fun. :)
Answer by Eric5h5 · Jan 12, 2011 at 08:16 PM
Aside from scale, one cause of too-slow rolling is not having a high enough max angular velocity in the physics settings.
What is a good value for max angualr velocity and what are the consequences of altering the value?
Just try things out. Save your project under a different name if you are worried about messing it up, and try things. $$anonymous$$ake a new barrel with super low angular velocity and see what happens, attach a constant velocity to another and see what happens, hell, set off an explosion next to one and see if it does what you want. $$anonymous$$ost of the stuff mentioned in the answers don't have anything to do with scripting and are pretty much, plug, play, and experiment. :)
Answer by Jesse Anders · Jan 12, 2011 at 08:11 PM
This may be too obvious, but have you tried playing around with different physics materials? (Also, make sure the masses of your objects are in proportion to the scale of the scene and your gravity settings.)