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
1
Question by NKolda · Oct 12, 2019 at 12:02 PM · collisioncollidercollider2d

Detecting empty collider

Alright so I think I'm struggling with something syntax related, not entirely sure. Right now, this code just makes it so the tagged objects take damage - it works. Although, I wanna get another bit of code that detects if the hitbox hasn't collided with anything, so I can do some functions for when that scenario happens. Is there a simple of way of doing this that I'm missing? alt text

1111111.png (14.5 kB)
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 misher · Oct 12, 2019 at 02:05 PM 0
Share

You question is not clear enough, please provide a full description of what are you trying to achieve.

avatar image NKolda misher · Oct 12, 2019 at 02:46 PM 0
Share

Ok so as of right now, when I press the down key, the player attacks and temporarily creates a hitbox, this code decides what happens when it collides with an "Enemy" object as well as a "bomb" object. When this hitbox is created, I want to be able to write some code for when the collider doesn't hit any other colliders. To be more specific, I want the field of view to shrink whenever the player misses (But I know how to do the shrinking part).

avatar image myzzie NKolda · Oct 12, 2019 at 06:17 PM 0
Share

You need logic for then a trigger is not triggered. That will never work in OnTriggerEnter. Ins$$anonymous$$d, set a bool for when it got triggered, after the attack, check that bool if something was triggered, if not, do your logic and reset the bool.

1 Reply

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

Answer by GrayLightGames · Oct 12, 2019 at 06:25 PM

Collider2D has a member function called OverlapCollider that will give you a list of any colliders that currently overlap it. So if you call this from Update or when you need you'll be able to check it for null. That will only help if your other objects have colliders. Alternatively, you could always just make a derived class from Collider2D with a bool hasCollided that you would default to false and set to true on collision. That would give you flexibility in case you need to check the object after the triggering object/collider has already left. Hope that helps!

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 NKolda · Oct 12, 2019 at 09:26 PM 0
Share

Yeah I was playing around with the second option for quite a bit - using booleans. Either I'm being dumb or they're sort of awkward to use in this scenario (I'm gonna assume the first one). Although, I've come up with a bootlegged solution where I've just added another collider which checks when the player attacks, running code when the player collides with that rather than anything else. Pretty grim right.

avatar image GrayLightGames NKolda · Oct 12, 2019 at 09:41 PM 0
Share

Not sure I follow, but sounds a bit bootlegged like you said... but hey if it works for you, why not? If you did just go with bools, it would just be something like:

 bool hasCollided;
 
 OnTriggerEnter2d(Collider2d col)
 {
   hasCollided = true;
   //The rest of your code here
 }
 
 CheckHasCollided()
 {
   if(!hasCollided)
   {
      //Whatever your zero collision code is
   }
   //If you want to reset the collider after the check
   hasCollided = false;
 }

This wouldn't be too awkward unless I'm missing something, whatever event triggers the collider check can just call CheckHasCollided(). If that's a player attack, is there a function you're calling to make that happen? Even if you need separate bools based on the colliding tag, might be easier to deal with than the collider you're talking about. Like I said though, if you have something that works for you, run with it and let's hope the Best Practices police aren't reading this post :)

avatar image NKolda GrayLightGames · Oct 13, 2019 at 07:53 PM 0
Share

Alright so I tried exactly this before going to the whole bootlegged thing. When doing it like that (with the bools), it detects all the misses until I hit an enemy for the first time, which is detected as a miss for some reason. After that, it goes into a pattern that I can't describe, detecting enemies as a miss, misses as enemies. This then swaps round whenever I throw a miss into a spree of enemy hits or vice versa.

I put the CheckHasCollided function into the player script with all this stuff.alt text

aaaaaaaa.png (19.0 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

192 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Tilemap Collider 2D preventing objects from moving 2 Answers

How do I get collisions between Tilemap Collider 2d and a Kinematic Rigidbody 2d? 1 Answer

Weird ContactPoint2D on two BoxCollider2D collision 0 Answers

Collision detection problem 0 Answers

How to make a PlatformEffector2D doesn't affect a specific layer? 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