- Home /
How to reduce bounce?
Hi, I'm creating a game with a ball and now what I want to do is to make it stop bouncing after few bounces. But now when my ball jumps and touches the terrain, it totally stops and speed is 0 at all directions.
My script
var jumpforse :float; var CanJump = true; var fallforse : float;
function Update () { if(Input.GetKey(KeyCode.W)) { rigidbody.AddForce (Vector3.forward * forse);
}
if(Input.GetKey (KeyCode.S)) {
rigidbody.AddForce (Vector3.back * forse);
}
if(Input.GetKey (KeyCode.A)) {
rigidbody.AddForce (Vector3.left * forse);
}
if(Input.GetKey (KeyCode.D)) {
rigidbody.AddForce (Vector3.right * forse);
}
if(rigidbody.velocity.magnitude > maxSpeed){
rigidbody.velocity = rigidbody.velocity.normalized * maxSpeed;
}
if(Input.GetButtonDown ("Jump"))
{
if(CanJump == true) {
rigidbody.AddForce (Vector3.up * jumpforse);
}
}
} function OnCollisionExit(collision : Collision){
if (collision.gameObject.name == "Terrain"){
CanJump = false;
audio.Play ();
}
}
function OnCollisionEnter(collision : Collision){
if (collision.gameObject.name == "Terrain"){
rigidbody.velocity = Vector3.up / fallforse;
}
}
Answer by robertbu · Dec 15, 2013 at 06:02 PM
Bounciness is controlled by the physic material of the colliders. To start go to Assets > Import Package > Physic Materials. This will give you a basic set. Then go to your ball and your terrain and click on the target symbol to the right of 'None (Physic Material)' and select one of the materials. Start with 'Bouncy'. If you need to make adjustments, you can create your own physic materials. Right click in the Project pane and select Create > Physic Material. You may also want to adjust the 'Drag' setting in your Rigidbody.
Your answer
Follow this Question
Related Questions
Bouncing Ball Game 3 Answers
Change bouncing angle with touching speed 1 Answer
Bouncy Ball Game 1 Answer
How To Make Ball Bounce On Touch 1 Answer