EDIT : [4/24/2016] Hello there.I’ve written a script for my 3D game and i wrote the part for jumping.The problem that i came across is that my character can double or triple or x*jump while i only want him to be able to jump once.I guess this is an issue caused by my isGrounded bool but i can’t find it.Below you will find my script and if you have any idea on how to solve this please replY!Thanks!
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
// Variables
public float speed;
public int jumpForce = 1000;
private bool isGrounded = true;
Rigidbody rb;
// Functions
void Start()
{
rb = gameObject.GetComponent<Rigidbody>();
}
void Update()
{
// Movement(L,R,U,D
float moveX = Input.GetAxis("Horizontal");
float moveY = Input.GetAxis("Vertical");
rb.velocity = new Vector3(moveX * speed, rb.velocity.y, moveY * speed);
if(Input.GetButtonDown("Jump") && isGrounded == true)
{
rb.AddForce(transform.up * jumpForce);
}
}
void OnCollisionStay()
{
isGrounded = true;
}
}