0
Answered

How to modify collider on runtime?

Andi Rutz 1 year ago in Game Creator updated by Marti (Lead Developer) 1 year ago 2

Regarding combat, I can't see to find a way to turn on/off colliders. When I get close to an enemy even without attacking the collider on the weapon touches the enemy and damages it. Id like it to wait till the attack input has been pressed. Any ideas?https://www.loom.com/share/4bea03c814fc4e48af1486f2009c3806 You can see it here.

Unity version:
Game Creator version:

Answer

+1
Answer
Answered

As @ProfPivec says, what you're looking for is enabling and disabling the Collider when the attack happens. A user called @Necka created a script that allows to enable/disable a Collider using the animation clip event system.

Here is the script:  AttackAnimEvent (1).cs

How to use it:

Drag and drop this script where the Animator component is and drag and drop the Collider object onto the corresponding field.

Now open the Animation Clip of your attack and scroll down to the bottom. Identify which frame should the attack start and which should end.

In each frame, create a new event and use the name StartAttack and EndAttack. This will effectively enable the Collider while the attack is being played.


The Animation Clip communicates with the script attached to the Animator and calls the StartAttack and EndAttack functions which enable and disable the Collider component attached.


PS: I can't tag a mentioned user. Nonetheless, all credit goes to the Discord user @Necka.

+1

If your collider is on a trigger game object, you can use the SetActive Action to turn it off and on. If you just want to toggle the collider itself, you can use the EnableComponent Action. 

+1
Answer
Answered

As @ProfPivec says, what you're looking for is enabling and disabling the Collider when the attack happens. A user called @Necka created a script that allows to enable/disable a Collider using the animation clip event system.

Here is the script:  AttackAnimEvent (1).cs

How to use it:

Drag and drop this script where the Animator component is and drag and drop the Collider object onto the corresponding field.

Now open the Animation Clip of your attack and scroll down to the bottom. Identify which frame should the attack start and which should end.

In each frame, create a new event and use the name StartAttack and EndAttack. This will effectively enable the Collider while the attack is being played.


The Animation Clip communicates with the script attached to the Animator and calls the StartAttack and EndAttack functions which enable and disable the Collider component attached.


PS: I can't tag a mentioned user. Nonetheless, all credit goes to the Discord user @Necka.