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 /
avatar image
0
Question by vov9923 · Jul 05, 2018 at 12:57 AM · collisionraycastjumpraycasthit2d

Physics2D Raycast stops detecting collision

I'm trying to use Raycasting in a 2D project for jumping. It works fine if I jump once, wait for the player to fall and jump again, but if I hold the jump button the player jump 2 times and then when it touches the ground again it doesn't detect that collision, so the player can't jump anymore since the "canJump" variable depends on that collision, it also doesn't detect it if I jump to another cube that also has the "Floor" tag, and it should make the jump variable true as well.

Edit: I just noticed that just before this happens, it detects 2 collisions (the player just hits the ground once), that happens once or twice and then it just stops detecting them.

Here's the code for jumping:

 height = gameObject.GetComponent<BoxCollider2D> ().size.y;
 
 RaycastHit2D hit = Physics2D.Raycast (new Vector2(transform.position.x,transform.position.y-(height/2)-0.001f), Vector2.down, 0.04f);
     
     
             if (hit.collider.tag == "Floor") {
                 
                 canJump = true;
             }
     
     if (Input.GetAxis ("Jump") > 0 && canMove && canJump) {
                 
                 rb.velocity = new Vector2 (
                     rb.velocity.x,
                     jumpForce
                 );
                 canJump = false;
             }
 







Comment
Add comment · Show 3
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 Shameness · Jul 05, 2018 at 01:57 AM 1
Share

Try to put first if statement below 2nd if statement. $$anonymous$$ight help.

avatar image vov9923 Shameness · Jul 05, 2018 at 02:58 AM 0
Share

Now I can jump more than 2 times by holding space , but if I keep holding it it stops jumping again at some point. And I still can't jump to another platform even if it has the same "Floor" tag, because if I do it won't detect the collision and I won't be able to jump again even if I go back to the first platform

avatar image Shameness vov9923 · Jul 05, 2018 at 04:05 AM 1
Share

Found this Q&A, its shows a solid way to check collision before jump. see if its helps you:

https://answers.unity.com/questions/196381/how-do-i-check-if-my-rigidbody-player-is-grounded.html

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

171 People are following this question.

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

Related Questions

Jumping with raycasts causing issues? 2 Answers

My Raycasts seem to sometimes miss 0 Answers

OnCollisionEnter2D is not working 0 Answers

How to find out in 2d the distance betwen beginning of the 2d raycast and the point of meeting with 2d collider. 2 Answers

How to check if a raycasthit detects an angle less than 45 degrees and touches the ground 2 Answers


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