Ball jump issue

I have this code:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody rb;
    private bool isGrounded;

    void Start ()
    {
        rb = GetComponent<Rigidbody> ();
        isGrounded = true;
    }
   
    void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        float jumpers = 0;
        if (isGrounded)
        {
            if (Input.GetKeyDown (KeyCode.Space))
            {
                jumpers = 15.0f;
                isGrounded = false;   
            }
        }

        Vector3 movement = new Vector3 (moveHorizontal, jumpers, moveVertical);

        rb.AddForce(movement * speed);

    }

    void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("Pickup"))
        {
            other.gameObject.SetActive (false);

        }
        if (other.gameObject.CompareTag ("Floor"))
        {
            isGrounded = true;
        }
    }
}

The problem is that I can only jump once. To state the obvious, all the floors are given the proper tag “Floor”. How can I fix this? Thanks.

It seems unlikely to me that your floors are triggers, are you sure you don’t want OnCollisionEnter instead of OnTriggerEnter?

Add some Debug.Log() statements and make sure your if statements are firing as expected.

1 Like

Wow I’m ashamed I missed that one out. Yep it worked the way you said, thanks a lot pal, you saved me some precious time :smile:

1 Like