Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unity 3D OnCollisionEnter

I’m trying to make my player jump only when they are touching the ground and to do so I made an OnCollisionEnter(Collision collision) function, then I made another function called jump which makes the player jump when the space button is pressed the on the CollisionEnter function I call this function however this does not call the jump function, what am I doing wrong? when the player collides with the ground though it does print It’s jumping as I have made a Debug.log check.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

OnCollisionEnter function is called only once, when your player collide the ground.
If you want to do that you have to use a "isGrounded" boolean variable which you set to true when is grounded (in OnCollisionEnter) and set to false when you press jump.
The jump control must be in the Update function.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading