- Home /
Object Bouncing of Others
I wrote a script which make the player move forward, backward, left, right, and up. It works fine. But when I collide with an object, the player bounces off. It is not intended to bounce of. I want it to just collide and do nothing.
The Script:
using UnityEngine;
using System.Collections;
public class CubeMove : MonoBehaviour {
public float fspeed;
public float bspeed;
public float lspeed;
public float rspeed;
public float jump;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown (KeyCode.W)) {
GetComponent<Rigidbody> ().AddForce (transform.forward * fspeed);
}
if (Input.GetKeyUp (KeyCode.W)) {
GetComponent<Rigidbody> ().AddForce (transform.forward * -fspeed);
}
if (Input.GetKeyDown (KeyCode.S)) {
GetComponent<Rigidbody> ().AddForce (transform.forward * -bspeed);
}
if (Input.GetKeyUp (KeyCode.S)) {
GetComponent<Rigidbody> ().AddForce (transform.forward * bspeed);
}
if (Input.GetKeyDown (KeyCode.A)) {
GetComponent<Rigidbody> ().AddForce (transform.right * -lspeed);
}
if (Input.GetKeyUp (KeyCode.A)) {
GetComponent<Rigidbody> ().AddForce (transform.right * lspeed);
}
if (Input.GetKeyDown (KeyCode.D)) {
GetComponent<Rigidbody> ().AddForce (transform.right * rspeed);
}
if (Input.GetKeyUp (KeyCode.D)) {
GetComponent<Rigidbody> ().AddForce (transform.right * -rspeed);
}
if (Input.GetKeyDown (KeyCode.Space)) {
GetComponent<Rigidbody> ().AddForce (transform.up * jump);
}
}
}
Why does it bounce?
What is your colliders physics material? And the mass of your rigidbody?
Answer by bogartrye · Jun 17, 2015 at 04:57 PM
Add a physics material to the player. You can change the properties of that physics material in the inspector. Change Bounciness to 0 and Bounce Combine to Minimum.
Answer by rhbrr5hrfgdfgw · Jun 17, 2015 at 07:32 PM
Its bounces because you using the 'Add Force' method which gives a force to your object, and when ever it collides(just like in real life) the object will bounce.I think that if you will increase the mass then this will not happen
Your answer
![](https://koobas.hobune.stream/wayback/20220613201028im_/https://answers.unity.com/themes/thub/images/avi.jpg)