Sphere is not using OnCollisionEnter/OnTriggerEnter/OnCollisionStay/OnTriggerStay functions
Hello,
I have recently tried to start a new game in unity, and I made a playground scene to test the mechanics and all. Currently, I have a ball that stays on the ground, can move, and jump, but I want to restrict the ball from jumping more than once until it lands back on the ground. However, I cannot get the ball to detect the ground with this code (attached to the ball):
using UnityEngine;
using System.Collections;
public class BallController : MonoBehaviour {
public float ballSpeed;
public float jump;
public float maxAngVel;
public float jumpCount = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float xSpeed = Input.GetAxis ("Horizontal");
float ySpeed = Input.GetAxis ("Vertical");
Rigidbody body = GetComponent<Rigidbody> ();
body.AddTorque (new Vector3(xSpeed, 0, ySpeed) * ballSpeed * Time.deltaTime);
body.maxAngularVelocity = maxAngVel;
if (Input.GetKeyDown (KeyCode.Space) && jumpCount == 0) {
body.AddForce (new Vector3 (0, jump, 0));
jumpCount = 1;
}
}
void onCollisionEnter (Collision col){
Debug.Log ("test");
if (col.gameObject.tag == "ground") {
Debug.Log ("Touching the ground");
jumpCount = 0;
}
}
}
Here is how my ball object is set up:
it has a child empty game object, with this currently on it:
The empty child is the actual sphere collider, while the collider on the parent is a trigger that has a radius a slight bit bigger than the child, for when I tried to use OnTriggerEnter/OnTriggerStay functions.
I have tried all 4 functions I mentioned in the title with no results. What am I doing wrong? [1]: /storage/temp/92155-unity1.png [2]: /storage/temp/92156-unity2.png