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 Asafmazor_49 · Jun 22, 2020 at 03:56 PM · functionwall jumpdebug.drawline

Having problem with debug.DrawRay

So I'm making a 2D platformer and I was trying to detect collision with the floor with a boolean function that has a Boxcast, it turned out perfect, I also added some debug rays at the coordinates of the boxcast so I could see it, turned out well again. The issue I'm having is that now that I want to recicle my code, so I can detect a wall (just change the values of the Boxcast and the rays), the rays aren't showing (I made shure to have Gizmos on). I dont understand why the first function shows and works, and the second one doesn't. Here's my code:*bc references my BoxCollider2D

 //check isGrounded
 private bool IsGrounded()
 {
     float extraDistance = .1f;
     RaycastHit2D raycastHit = Physics2D.BoxCast(bc.bounds.center, bc.bounds.size, 0f, Vector2.down, extraDistance, floorLayerMask);
     Color rayColor;
     if (raycastHit.collider != null)
     {
         rayColor = Color.green;
     }
     else
     {
         rayColor = Color.red;
     }
     Debug.DrawRay(bc.bounds.center + new Vector3(bc.bounds.extents.x, 0f), Vector2.down * (bc.bounds.extents.y + extraDistance), rayColor);
     Debug.DrawRay(bc.bounds.center - new Vector3(bc.bounds.extents.x, 0f), Vector2.down * (bc.bounds.extents.y + extraDistance), rayColor);
     Debug.DrawRay(bc.bounds.center + new Vector3(bc.bounds.extents.x, - (bc.bounds.extents.y + extraDistance)), Vector2.left * (bc.bounds.extents.x * 2), rayColor);
     return raycastHit.collider != null;
 }

 //check WallHugging
 private bool WalHugging()
 {
     float extraDistance = .1f;
     RaycastHit2D raycastHit = Physics2D.BoxCast(bc.bounds.center, bc.bounds.size, 0f, Vector2.right, extraDistance, floorLayerMask);
     Color rayColor;
     if (raycastHit.collider != null)
     {
         rayColor = Color.blue;
     }
     else
     {
         rayColor = Color.red;
     }
     Debug.DrawRay(bc.bounds.center + new Vector3(0f, bc.bounds.extents.y), Vector2.right * (bc.bounds.extents.x + extraDistance), rayColor);
     Debug.DrawRay(bc.bounds.center - new Vector3(0f, bc.bounds.extents.y), Vector2.right * (bc.bounds.extents.x + extraDistance), rayColor);
     Debug.DrawRay(bc.bounds.center + new Vector3(bc.bounds.extents.x + extraDistance, - bc.bounds.extents.y), Vector2.up * (bc.bounds.extents.y * 2), rayColor);
     return raycastHit.collider != null;
 }
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

2 Replies

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

Answer by Asafmazor_49 · Jun 26, 2020 at 04:34 PM

Hey, I found a solution, it turned out that I needed to reference the method for it to show, I just made a quick reference changing the rigidBody velocity and it shows. Eitherway Thanks @N8- for your answer.

Comment
Add comment · Show 1 · 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 N-8-D-e-v · Aug 28, 2020 at 01:36 PM 0
Share

awesome, glad it worked out!

avatar image
0

Answer by N-8-D-e-v · Jun 22, 2020 at 05:09 PM

Try using gizmos.drawray, and using that in the OnDrawGizmos() method, here's what I mean https://docs.unity3d.com/ScriptReference/Gizmos.DrawRay.html

Comment
Add comment · Show 1 · 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 Asafmazor_49 · Jun 23, 2020 at 05:55 PM 0
Share

Hey, this works, not precisely for what i want to do, but it works. Still, I dont understand why the first function (IsGrounded) displays the rays perfectly, and the next one doesnt :(.

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

130 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

Related Questions

is it possible to use a rotation on a Vector3? 3 Answers

accessing a function? 1 Answer

How do I make a callback run? 1 Answer

Weirdness.. Why does putting yield in function corrupt commands? 1 Answer

problem with calling a function from THIS script, on an object that I find with THIS script. 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