Hello there. I'm a beginner in Unity3D and C# So I'm basically trying to recreate Google Chrome's offline Dinosaur game as my semester project and I'm stuck with this particular issue with colliders. I have a separate ground object and a separate player object (dinosaur) . So when spacebar key is pressed, the player object jumps. So I'm trying to figure out a way to prevent key spamming so as to prevent multiple jumps while in air. I thought of adding a separate empty game object with box collider 2d and rigidbody 2d (kinematic option ticked) as children to both player and ground object and write a separate script for collision between player object and ground object. I tested the collision by printing a log in the console and it seems to work but it detects only one collision (the first one) even after multiple jumps. Help please ? Thank you for your time.
Could you post the code you're using for the player? It'd make it easier to see if there's a problem with the code or if there's something else that needs to be adjusted.
Have a look at the unity 2D platformer tutorials. They have a great example on how to do this for 2D, but should work the same in 3D. The basic principle is: - Have a boolean to track if the object is jumping - When the jump button is pressed, only run the jump method if Jump is false - Set jump to true at the start of the jump method - Have a collider on your ground objects that when collideded with run a method
Sorry for the late reply ! And thank you for your suggestions. I found a different way to get around the issue not long after I posted this thread. Code (CSharp): if ((Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0)) && Time.time > can_jump) { set_flag = true; can_jump = Time.time + jump_delay; }