Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ridley123 · Jun 23, 2014 at 02:01 PM · 2dlinecastgrounded

Phisycs2D.Linecast doesn't work correctly

Sorry for my poor English guys :D

I have some problem with this method. I tried to make the object jump. But "isGrounded" randomly sets to "true" when groundCheck is not in position of "Ground"-layer objects.

How can I fix this problem?

There is a code from Update:

     var ballPos: Vector2 = new Vector2 (ballContainer.transform.position.x, ballContainer.transform.position.y);
 
     var grCheckPos: Vector2 = new Vector2 (groundCheck.position.x, groundCheck.position.y);
 
     isGrounded = Physics2D.Linecast(ballPos, grCheckPos, 1 << LayerMask.NameToLayer("Ground"));
     
     if (isGrounded)
     {
         Debug.Log("Grounded");
         jumpCheck = true;
     }
     
     if (!isGrounded)
     {
         jumpCheck = false;
         
     }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Pyrian · Jun 23, 2014 at 05:26 PM

Wow, we so often see questions about collisions not occurring, it's almost refreshing to see a question about mystery collisions instead. It's also much easier to find out what's happening.

You could try something like:

 RaycastHit2D GroundCheck = Physics2D.Linecast(ballPos, grCheckPos, 1 << LayerMask.NameToLayer("Ground"));
 if (GroundCheck) Debug.Log("Ground hit " + GroundCheck.collider.name + " at " + 
     GroundCheck.point.ToString() + "(" + ballPos.ToString() + " - " +
     grCheckPos.ToString() + ")");

Then you'll be able to see exactly what and where the Linecast is "randomly" intercepting something.

Comment
Add comment · Show 6 · Share
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 Pyrian · Jun 23, 2014 at 05:27 PM 0
Share

I may have the syntax off in that code snippet - you're using JavaScript and I'm more accustomed to C# - but the general idea should work.

avatar image Ridley123 · Jun 23, 2014 at 09:33 PM 0
Share

Thanks for your reply, Pyrian :)

I tried this trick and that's what I get.alt text

I've marked up debug message where GroundChecker sets to True incorrectly. (take a look at the Y-coordinate). I have no any objects in Ground-layer except this pillars.

But ball is colliding with this pillars somehow :( I have no idea what is it.

безымянный.png (223.1 kB)
avatar image Ridley123 · Jun 23, 2014 at 09:46 PM 0
Share

Another proof of paranormal colliding :Dalt text

123.png (265.2 kB)
avatar image Pyrian · Jun 23, 2014 at 10:07 PM 0
Share

Well done! We've ruled out any problems with the positions, and it looks like the collision is in the expected area, and we know it's hitting a Pillar(Clone). $$anonymous$$y next thought is - are we sure we know which pillar it is hitting? $$anonymous$$aybe add a number to the name of each pillar as it is instantiated.

Also... Are you sure you can't divine any pattern in when this occurs? If this really is a bug, we'll want to replicate and report it.

Let's assume for a second that it's actually a bug in Linecast. Have you considered trying Raycast? It's really easy to switch back and forth. You could just use "ballPos", "grCheckPos - ballPos", and "(grCheckPos - ballPos).magnitude".

avatar image Ridley123 · Jun 24, 2014 at 08:08 AM 0
Share

Yes, I tried to use it. Raycast is working the same way for me(

I've add the number to pillar and find out that ball hits distant fresh generated pillar O_O

Just take a look alt text

безымянный.png (235.7 kB)
Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Check if 2D Player is grounded with Physics2D.Linecast 1 Answer

How to check for the ground in Unity 2D for Jumping 1 Answer

issues with jumping and linecast2d and raycast2d 0 Answers

unity2d issue with linecasts. 1 Answer

Unable to check if grounded 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