Wall Roll

Hi all i have some rolling problem.
I have my rolling script and it rolles my sphere nicely but when it hits someting solid like a box it just stops.Iwanted it to like keep rolling so it looks more natural and better.I draw i picture so it can be understood.If someone can help.Plz

Here’s the script.

// speed of the ball
var speed = 5.0;
var radius = 5.0;
private var velocity : Vector3 = Vector3.zero;

function Start(){
	transform.localScale = Vector3.one * radius * 2;
	var hit : RaycastHit;
	if(Physics.Linecast(transform.position, transform.position - Vector3.up * 1000, hit)){
		transform.position = hit.point + Vector3.up * radius;
	}
	// add a rigidbody if we dont have one.
	if(!rigidbody)
		gameObject.AddComponent(Rigidbody);
	// set the mass according to the radius.
	rigidbody.mass = 40* radius;
}

function FixedUpdate () {
	// let see if our body is on the ground.
	var hit : RaycastHit;
	var isGrounded = Physics.Raycast(transform.position, -Vector3.up, hit, radius * 1.5);
	
	// base movement off of the camera, not the object.
	// reset the camera's X to zero, so that it is always looking horizontally.
	var x = Camera.main.transform.localEulerAngles.x;
	Camera.main.transform.localEulerAngles.x = 0;
	a
	// now collect the movement stuff This is generic direction.
	var direction = Vector3(Input.GetAxis("Horizontal"),0);
	
	// prevent the ball from moving faster diagnally
	if(direction.magnitude > 3.0) direction.Normalize();
	
	// If we are grounded, then lets see if we want to jump.
	if(isGrounded  Input.GetKeyDown(KeyCode.Space))
		rigidbody.AddForce(Vector3.up * rigidbody.mass * 350);
	
	// if we arent pressing anything, dont mess with the physics.
	if(direction.magnitude > 0){
		// convert isGrounded into something we can use
		var modifier = isGrounded ? 3.0 : 0.5;
		// lets set the direction according to the camera now.
		direction = Camera.main.transform.TransformDirection(direction) * speed * 2;
		// lets take the downward velocity from the current so that we dont get wierd physics results
		direction.y = rigidbody.velocity.y;
		
		// Now, lets keep track of a velocity.
		// This will let the ball move while we are not pressing anything.
		rigidbody.velocity = Vector3.Lerp(rigidbody.velocity, direction, modifier * Time.deltaTime);
		// Now, lets break the rotation out from the movement.
		var rotation = Vector3(rigidbody.velocity.z,0,-rigidbody.velocity.x) * 2;
		
		
		// Lets add some spin to make the ball move better
		rigidbody.angularVelocity = Vector3.Lerp(rigidbody.angularVelocity, rotation, modifier * Time.deltaTime);
	}
	
	// return the camera's x rotation.
	Camera.main.transform.localEulerAngles.x = x;
}

849885–31753–$WallRoll.bmp (602 KB)

Bump.

You want the ball to slide the box? You want the ball to hit the box and bounce back? What do you mean by “keep it rolling”? It’s hitting a solid object.

I mean when my ball is moving its rolling and thats good, but when it hits something solid(wall,box…)it stops rolling and it freezes rolling and keeps moving freezed so it looks bad.I want to keep rollin even when it hits something solid.

Try yourself to understand.Just put a sphere and a box in front of it .Try to move to box it will hit it and stop rotatting.

bump?

Try either using AddTorque or rotating the mesh gameobject manually.