Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collision with RigidBody2D #84

Open
frostblooded opened this issue Aug 9, 2017 · 2 comments
Open

Collision with RigidBody2D #84

frostblooded opened this issue Aug 9, 2017 · 2 comments

Comments

@frostblooded
Copy link

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?

@frostblooded frostblooded changed the title How to detect when colliding with enemy Collision with RigidBody2D Aug 9, 2017
@akshinmustafayev
Copy link

same problem here. somebody can fix this?

@gsgilman
Copy link

gsgilman commented Nov 8, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants