Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Teleight · Sep 27, 2021 at 11:46 PM · bulletoverlapsphereshmup

How to make a Shmup Graze mechanic

I'm making a bullet hell and I really wanna add a graze mechanic, however I can't figure out how to make the script only graze bullets once per bullet. I'm using Physics.OverlapSphere to get a list of the bullets near me, however it updates every frame, so it will return true for the same bullet multiple times if it has not yet left the radius of the OverlapSphere. any help would be greatly appreciated, and I can give more context if required, Thanks.

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 Eno-Khaon · Sep 28, 2021 at 04:02 AM

Rather than using Physics.OverlapSphere(), it might be more sensible to create a trigger collider around the player, then keep track of bullets that enter and leave its range using OnTriggerEnter() and OnTriggerExit().

Comment
Add comment · Show 4 · 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 Teleight · Sep 28, 2021 at 04:12 AM 0
Share

Yeah the only issue with that is if I create a child object and put a collider on it, unity will treat that graze collider as the player's hitbox as well (since my parent has the player's hitbox), meaning that enemies only have to hit the graze collider instead of the smaller hitbox they're intended to hit. However you're completely right, I'll probably just have to make the parent a child and do it like you suggest.

avatar image Eno-Khaon Teleight · Sep 28, 2021 at 04:36 AM 0
Share

Are you already using a trigger collider as the main "collision" detection, then?

If so, you could take this approach, then:

Attach *BOTH* trigger colliders to child objects of your main player (i.e. "grazing" trigger and "impact" trigger). Give each child a script consisting only of OnTriggerEnter() and OnTriggerExit() (as applicable), where all those functions need to do is send a message to a script on your main player GameObject.

You would be able to keep track of the results of those triggers like you already are, but where the two trigger colliders would activate independently.

For a very simple example:

 // Script on main object:
 public class ParentWithRigidbody : MonoBehaviour
 {
     public void MessageFromChildA(string message)
     {
         Debug.Log("ChildA trigger -> " + message);
     }
     public void MessageFromChildB(string message)
     {
         Debug.Log("ChildB trigger -> " + message);
     }
 }

 // -------------------------------

 // Script on Child A
 public class ChildTriggerA : MonoBehaviour
 {
     public ParentWithRigidbody parentRB;
 
     private void OnTriggerEnter(Collider other)
     {
         parentRB.MessageFromChildA(other.gameObject.name);
     }
 }
 
 // -------------------------------
 
 // Script on Child B
 public class ChildTriggerB : MonoBehaviour
 {
     public ParentWithRigidbody parentRB;
 
     private void OnTriggerEnter(Collider other)
     {
         parentRB.MessageFromChildB(other.gameObject.name);
     }
 }


Edit: Fixed a significant, silly, obvious, yet largely unimportant typo.

avatar image Teleight Eno-Khaon · Sep 28, 2021 at 04:42 AM 0
Share

Oh my gosh that's genius I had never thought of doing things like that it's so simple and concise compared to what I was doing. I was dealing with a bunch of AI stuff recently that had me thinking I had to use OverlapSphere or CheckSphere to find other collisions. Thanks a bunch! It's really nice to have met a stranger with so much dedication to helping me :D

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

126 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

Related Questions

Bullet Pattern for Bullet Hell 1 Answer

How do I create bullet patterns (multiple bullets, different world positions) 3 Answers

Ship won't shoot right in SMHUP. Help?? 2 Answers

SHMUP Boss, changing firing rate 1 Answer

how to rotate to face camera point in 2D 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