- Home /
Rolling mable... rigid body?
I am trying to make a marble that moves constantly... it is going to be able to move in all directions.
So far i have used the transform.Translate to move the object but this doesnt have the effect that i desire. I have seen around that adding a rigidbody to the ball and move it using that is the best option.
I have no idea of how to approach using the rigid body... can anyone help me understand how i use the rigidbody to get the marble rolling.
All help is much appreciated =)
Answer by ztripez · Nov 24, 2011 at 09:31 PM
It's very easy. Just apply a rigid body to the marble, add some mass to it. Since it's a physics engine it work on physics rules. When you have a mass on the marble all you need is to apply some force to the object. To test the physics i would recommend to add a Terrain to test it out.
To push the object forward (The worlds forward, not the object's):
float force = 10;
rigidbody.AddForce(Vector3.forward * force);
And for a 2D game, the same works well with a Rigidbody2d: if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow)) { player.AddForce(Vector2.right * 10); }
where 10
can be replaced with a variable of type float
, like playerSpeed
.