- Home /
Make Enemy Solid Object
I have a cube set up as a collider in order to do damage when the character touches it. However, this means he goes through him. I have a rigidbody attached, but I can't have it behave as a collider if it's solid. Is there a right way to do this?
Do you mean the collider is setup as a trigger? The box should not go through the character if the "Is Trigger" flag is clear. A standard box comes with a collider and should not have to be "set up."
The standard cube did have a collider and the only setup I did was checking IsTrigger. The player script uses the OnTriggerEnter function to be hurt by the enemy.
Answer by robertbu · Mar 24, 2013 at 04:28 AM
Turn off the "Is Trigger" flag and and instead use OnCollisionEnter() to catch the contact. This will allow the player to be hurt by the enemy but the player will not go through the enemy.
When I do this, jumping while bumping the player against the enemy for some reason throws him into the air. While amusing, not the intended behaviour. Why might this happen?
your player has too much mass or your enemy has to little
Collisions impart force.
You can use on collision enter to neagte it somehow or increase the mass of the enemy or decrease the player mass.(i suggest dropping player mass so he pushes everything less)
Use a character controller ins$$anonymous$$d of a Rigidbody if you want to "get rid" of the collision "throwing" behavior.
The character controller always wants to replace the collider. How do I set up the character controller to replace the collider's functionality? If I can't, why does it insist on replacing my collider? This is on the enemy, though. I've also removed the rigidbody from my Player with no effect on anything.
You can use OnControllerColliderHit() for the character controller to detect a hit.
Answer by sparkzbarca · Mar 24, 2013 at 05:31 AM
if for some reason you want both a trigger and a collider (just touching for damage wouldnt need one but like a radius around him that hurts you just being near for example)
if you want that you can attach an empty game object with a trigger and size it and then have the collider be the thing attached to him and the trigger just an empty object that follows him around
The collider will suffice for my needs, I think, but the trigger was the only one that seemed to do what I wanted. I'm new to Unity, and didn't think to use the Collider...though I'm having a bit of a problem with it, which you can see described in my response to robertbu's answer.