- Home /
I facing a problem when i click jump key and moving left and right direction it constantly fly towards its direction.How to set the jump?
void Update () {
key = LayerMask.GetMask ("Platform");
isGrounded = Physics.Linecast (transform.position, player.transform.position, key);
if (Input.GetKey (KeyCode.LeftArrow)) {
rb.velocity = new Vector3 (5f, 0f, 0f);
}
if (Input.GetKey(KeyCode.RightArrow)) {
// rb.velocity = new Vector3 (-5f, 0f, 0f);
rb.AddForce(new Vector3(-50f,0f,0f));
}
if (Input.GetKeyDown(KeyCode.Space) && (isGrounded)) {
rb.AddForce(new Vector3(0f,600f,0f));
// transform.position += Vector3.up 20 Time.deltaTime;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612161405im_/https://answers.unity.com/themes/thub/images/avi.jpg)