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 Leucaruth · Jan 12, 2016 at 05:26 PM · rigidbody2dphysics2dcollider2dtriggers

Unmoving Colliders2D not triggering OnEnterTrigger

Hi.

I'm doing a platformer game where the protagonist has a sword. Sometimes there are objects he has to smash several times for being able to advance.

For the sword I have a simple BoxCollider2D set with IsTrigger and I enable it whenever i need to attack (Just an Input.getkeydown) and it keeps active for 0.25 seconds before disabling it again. If I keep pressing the attack button I repeat the attack in the same pattern, I don't move the collider in all this time, only enabling and disabling it. This collider has a Kinematic RigidBody2D attached set with Continuous Collision Detection.

The Object I need to smash has another BoxCollider2D and RigidBody2D with the same configuration as the sword and a "Destructible" layer asigned.

For the Sword Script I have just a simple code:

void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.layer == LayerMask.NameToLayer("Destructible")) Debug.Log("Hitting Object"); }

When I make the collider appear, the OnTriggerEnter reacts and shows the "Hitting Object" message. The problem is that the following hits, as neither Collider2D moved (only enabled and disabled one of them), Unity don't recognize the "OnEnterTrigger" anymore.

I would like to know if there is any way around it because its making me frustrated, I dont want to make a random move to the collider so it detects the OnTriggerEnter again.

I thought about using Physics2D BoxCastAll (as it can hit several objects) but as I need to be able to hit for 0.25 secs and only once I dont want to use a Dictionary of hit objects, or something similar, for the BoxCast duration.

I really appreciate any help you can provide

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 L33T_Rakshasa · Mar 16, 2018 at 03:14 PM

So in your console it doesn't show multiple logs of the occurrence? If I understand your issue correctly; the issue is from enabling and disabling the trigger while inside the trigger bounds?

Comment
Add comment · 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

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

38 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

Related Questions

Do I need Rigid2DBody if I don't plan to use physics? 2 Answers

Which is collider and which is othercollider? 1 Answer

OnTriggerEnter2D executed once 0 Answers

Physics 2D with tile collider corner problem 2 Answers

Had to turn off gravity scale, but now player goes through walls 0 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