Rolling Marble

Hey,

This is probably really simple, but how to I make a marble look like it’s rolling when i move it forward?

Thanks.

You have to attach a rigidbody to it, and to move it forward, you have to apply force on it when you press forward.

Don’t let it puzzle you, it’s a really basic script.

Still trying to figure it out, but with no luck. I’m not exactly good at scripting.

Could you post the script?

I don’t know much about rigidbodies, but have you looked at the scripting refernce?

Alternatively, i saw this today.
http://www.indiegamemarket.com/product/19-rolling-ball-sample-project

OK, I got the rolling effect with this:

function FixedUpdate () {
	if(Input.GetButton ("RollForward")){
		transform.Rotate (10, 0, 0);
	}
	
	if(Input.GetButton ("RollBackward")){
		transform.Rotate (-10, 0, 0);
	}
	
	if(Input.GetButton ("RollLeft")){
		transform.Rotate (10, 0, 10);
	}
	
	if(Input.GetButton ("RollRight")){
		transform.Rotate (-10, 0, -10);
	}

}

Only, I dont know how to explain this, but I would like to find a way to rotate the texture instead of the whole thing, because, say, when i move it left, it’s rotation is changed, so when it moves forward again it doesnt look right.

Don’t use rotate, use rigidbody.AddForce instead.

Not Working for me. I’m not trying to make it move. I already have that part. I’m trying to give it the illusion of a rolling marble by rotating it when it moves.

If you want physics working ok, you can´t modify directly the x,y and z, and rotating by youself… you have to use the rigidbody methods.

OK, so i have a character controller, mouse look, and fps walker attached with a camera following it. Should i get rid of the fps walker?

function FixedUpdate () {
	if(Input.GetButton ("RollForward")){
		rigidbody.AddForce (10, 0, 0);
	}
	
	if(Input.GetButton ("RollBackward")){
		rigidbody.AddForce (-10, 0, 0);
	}
	
	if(Input.GetButton ("RollLeft")){
		rigidbody.AddForce (0, 0, 10);
	}
	
	if(Input.GetButton ("RollRight")){
		rigidbody.AddForce (0, 0, -10);
	}

}

???
I’m confused. :?:

…?

Why no answer?

Your question was answered. Why no initiative?

Get rid of the FPS walker. Just add a rigidbody to the marbe, and a camera to follow it. Don’t use rotate, just add force and it will rotate with physics.

Imagine yourself pushing a big marble, it would rotate itself with the applied force, it wouldn’t go straight without rolling. Same applies for physics.

OK, thanks everyone.

I think I have it now (mostly), but I have a few physics questions, like how to make the ball slow down as it goes up a slope, and accelerate as it rolls down

Using the addForce to move the marble makes it subject to world physics and gravity. Once you have the marble moving with the addForce, you don’t have to modify anything to have it gain speed rolling down a hill or slow when going up a hill.

Edit: You can tweak the speeds it speeds up and down by modifying the physics objects attributes. It will be nicely labeled in the inspector when the ball/marble is selected in the scene.

Well, mostly it does, but if i let go of the controls while it is on a slope, it slowly rolls down at a constant speed, whereas i want it to gradually speed up as it rolls down. It’s the same with going up, where it doesnt slow down gradually as it goes up a slope, but more like slows down in the beginning then slowly moves up at a constant speed. Is there a way to do this, to make it more realistic?

EDIT: I also want the ball to bounce when it falls off of an edge, which it currently does not do.

Anyone know how to do the above?

http://unity3d.com/support/documentation/Manual/Physics.html

Towards the bottom of the page it contains all the information you need. Look into the physics material and dynamic friction for the resistance based on material.

Your marble should contain a rigidbody sphere, to adust its properties read this manual page, it should help you find out just exactly what you need to tweak.

The drag for the rigidbody is what you would use to have the air give resistance for rolling back down. Also, playing with mass will change its behavior. Basically Rigidbody mass and drag will need to be adjusted, and the floors should have a physics material that has the proper surface properties for bounce, resistance etc. Those are what you need to play around with to get the right effect.

I haven’t tried this myself, but to make a rubber ball I assume adding a physics material to the ball ridgidbody would enable it to have bounce property itself, instead of the floor needing that property the bounce property. Then you can use the balls physics material property to change its bounciness when set to “rubber” for example.