• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

A box collider 2D (Is Trigger marked) stops my player from moving which has rigidbody 2D 1 Answer

OnTriggerEnter2D executed once 0 Answers

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

Which is collider and which is othercollider? 1 Answer

Physics 2D with tile collider corner problem 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges