You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The enemies in my game are regular enemies, but don't collide with the character. As far as I can see, this is supposed to work like that because of the nature of the character controller. So how do I detect when I have collided with the enemy? I just want for rigid bodies that collide with the character (player) to get the event OnCollisionEnter2D. Is there a way to do that?
The text was updated successfully, but these errors were encountered:
frostblooded
changed the title
How to detect when colliding with enemy
Collision with RigidBody2D
Aug 9, 2017
If you want collision like you have with the level, make sure that on your player's platform mask you have the enemy's layer selected and on the enemy's platform mask you have the player's level selected.
This will trigger the onCollisionCollider event.
However, you probably want special behavior defined for colliding with an enemy, so you will want to use the OnTriggerEnter/Exit/Stay events.
Do get the trigger to work properly, make sure that you have the enemy's layer selected on the player's trigger mask and the player's layer selected on the enemies trigger mask. This will trigger the "Trigger" events whenever the two players collide.
Side note, if you attach a collider to a child object of the object that contains the CharacterController2D
script, it will send Trigger events but not collision events, this can be useful for various things.
The MovementController in the Demo scene of this repo shows you how to listen for the Collision and Trigger events.
Hopefully this helps.
P.S. I am a Unity N00B so take all this with a huge grain of salt.
The enemies in my game are regular enemies, but don't collide with the character. As far as I can see, this is supposed to work like that because of the nature of the character controller. So how do I detect when I have collided with the enemy? I just want for rigid bodies that collide with the character (player) to get the event OnCollisionEnter2D. Is there a way to do that?
The text was updated successfully, but these errors were encountered: