A sticky problem

My main character uses a character controller to move about. I find this much more simple than other means. However, my monsters use colliders and rigidbodies to move about. My problem is due to this difference, earlier code will not work. Namely if I want to attack a monster it works, but if the monster wants to attack ME, it does not work.

Is there anyway I can fix this without changing my character over to capsule colliders and rigidbodies, then rewriting alot of the code I have and then adding even more new code?

I’m very late into the project and I’d really be grateful if anyone could help.

Situation Recap:
Player holds a weapon that switches trigger on/off when swung.
Monsters take damage when the trigger is on, this works.

Monster has a capsule collider and rigidbody connected.
I want the monster to punch the player and deal damage on collision, This does NOT work.

Yes, Character Controllers will not fire OnCollisionEnter(), but rigidbodies that hit the CharacterController will, so just code it from the enemy’s perspective instead:

function OnCollisionEnter(other : Collision){
	if(other.gameObject.tag == "Player"){

Also, CharacterControllers will still fire OnTriggerEnter(), so you could also use triggers for the enemy’s attacks just like you are for the player’s attacks.

I think it would be better to keep it encapsulated within your player, as taking damage will have more use within your player class (i.e. if you want to take damage via obstacles, such as falling beams, lava, ill tempered sea bass etc).

Whereas, if you code an inflictDamage function from your enemies perspective you’ll have to do this for EACH different enemy and/or obstacles, and other items that might inflict damage.

You’ll have to use the OnControllerColliderHit in order to get collision detection from against your player.

Thus (this code should go in your player class)

    function OnControllerColliderHit(obj : Collision) 
      if(obj.gameObject.tag == "Enemy") || (obj.gameObject.tag == "CrazyMonkey") 

Or use a switch statement in order to inflict different amounts of damage :slight_smile: