Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by MGFlow58 · Apr 17, 2017 at 07:29 PM · c#collision3dbeginnerball

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: alt text

it has a child empty game object, with this currently on it: alt text

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

unity1.png (53.4 kB)
unity2.png (23.1 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sergio7888 · Apr 17, 2017 at 07:56 PM 0
Share

Your Ground object has the tag "ground" on it?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help designing a sinking platform that lets objects pass through from underneath 1 Answer

How to let a object dodge a collision? 0 Answers

Collision Detection between two different Prefabs doesnt work 1 Answer

Who collided first 0 Answers

Unity3d OnCollisionEnter not firing 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges