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 /
  • Help Room /
avatar image
0
Question by Richarrd82 · Sep 04, 2016 at 09:54 AM · c#unity 2dplatformoverlap

Physics2D.OverlapCircle doesnt work

Hello guys!

I have a problem with Physcis2D.OverlapCircle. In one tutorial i saw somebody use it as ground detector.

     public bool grounded;
     public float groundCheckRadius;
     public LayerMask WhatIsGround;
     public Transform groundCheck;

  void FixedUpdate()
     {
     grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, WhatIsGround);
     }

And it works nicely, so i thought i would use it to detect if player is standing on top of a platform. I tried to do it the same way but i cant get it to work properly. What i did is a created empty gameObject on each platform. Then i put a script on it where i wrote:

 public bool onTop;
 public LayerMask whatIsTop;
 public float topCheckRadius;
 public Transform topCheck;
 void FixeUpdate()
 {
     onTop = Physics2D.OverlapCircle(topCheck.position, topCheckRadius, whatIsTop);

     if (onTop)
     {
         Debug.Log("Works!");
     }
 }

Then in inspector i put the empty gameobject as the topCheck.position, i put some value for the topCheckRadius and lastly i create a layer called Top and then i select it in the WhatIsTop layermask.

But when i jump on the platform with player nothing happens.

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

Answer by Dream_in_code · Sep 04, 2016 at 10:55 AM

You dont need to make gameobjects on each platform instead add a gameobject as a child named "groundcheck" to your player.

public bool onTop;

public LayerMask whatIsTop;

public float topCheckRadius;

public Transform topCheck;/drag and drop "groundcheck" here else it wont work//

void FixeUpdate()

{

  onTop = Physics2D.OverlapCircle(topCheck.position, topCheckRadius, whatIsTop);

} Adjust the "ground check" gamebject at the bottom of your player Inside "whatisTop" make sure Ground layer is selected.

alt text alt text


screenshot-2.jpg (21.7 kB)
screenshot-1.jpg (16.5 kB)
Comment
Add comment · Show 2 · 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 YoYoYoYo_111_PiPi · Oct 31, 2017 at 10:08 AM 0
Share

What if we want to add multiple objects for groundcheck? How would the code go? Would we have to create multiple groundCheckRadius as well? Pertaining to his code above:

 void FixedUpdate()
      {
      grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, WhatIsGround);
      }
avatar image hghjgfjgf · Mar 29, 2020 at 04:26 PM 0
Share

if you want to detect all objects inside the circle, you use

colliderList = Physics2D.OverlapCircleAll( same parameters );

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

6 People are following this question.

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

Related Questions

See if objects overlap when user taps the screen 0 Answers

How to change animator states from a key press? 1 Answer

How do I Detect if an object has made a full rotation and gradually change its color 1 Answer

Error, Raycast2D call function in self script on duplicate object. 0 Answers

Find nearest enemy object in radius 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