Hello! I made a Script for 3D Movement and I’m new, that brings a lot of problems, well only one for now. If I spam Jumping in the Game I wont be able to jump anymore does it have something to do with the code or the objects?
{
public float Movespeed = 5f;
private float Movejump = 5f;
private Rigidbody rb;
private bool grounded = true;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float horizontal = (Input.GetAxis("Horizontal") * Time.deltaTime * Movespeed);
float vertical = (Input.GetAxis("Vertical") * Time.deltaTime * Movespeed);
transform.Translate(horizontal, 0f, vertical);
if (Input.GetButton("Jump") && grounded)
{
rb.AddForce(new Vector3(0, Movejump, 0), ForceMode.Impulse);
grounded = false;
}
if (grounded == false)
{
Movejump = 0;
}
if (grounded == true)
{
Movejump = 5;
}
}
private void OnCollisionEnter(Collision other)
{
if(other.gameObject.tag == "Boden")
{
grounded = true;
Debug.Log("Im working");
}
}
}