- Home /
My sword pushes enemies around?
Literally just started using Unity yesterday, and I'm slapping together a little third person action game to learn the ropes and try to get a grip on C#.
I currently have a player that moves around correctly, and an enemy that is able to follow the player around.
I gave the player the ability to transition into an attacking animation when the player clicks LMB, and the enemy correctly detects when its been struck by the sword and plays a "damage" animation.
The only issue is that in order for the sword to detect collisions with the enemy, and in order for the enemy to use the NavMesh, I had to give it a RigidBody, and when the player's sword hits the enemy, it gets pushed around by the sword.
I had a little workaround where the enemy got RigidBody.isKinematic enabled briefly when it was hit, but this doesn't work all of the time.
I'm sure there's a much better way to handle this, but like I said, I'm new and would appreciate the help.
The player has a Character Controller, the sword bone of the model has a capsule collider that is parented by the sword, so it sticks to it, and the enemies have a RigidBody, NavMeshAgent, and Capsule Collider.
EDIT: to clarify, the player model itself pushes the enemy around; the sword is part of the player model.
Answer by mwbranna · Oct 17, 2014 at 10:17 PM
If you don't need the sword to bump anything around, you can use triggers. Triggers are like colliders except don't actually bump stuff, they just allow for use of the OnTriggerEnter() function and similar functions to detect overlapping objects. To make a collider a trigger, check the "Is Trigger" box in the collider in the inspector.
Ah, alright.
I made the sword's collider a trigger, and changed the code to onTriggerEnter ins$$anonymous$$d, but previously I had it set up as onCollisionEnter (Collision collision){
so that I could find which object it was colliding with, and that doesn't seem to work with onTriggerEnter; It throws the error:
"Script error: OnTriggerEnter This message parameter has to be of type: Collider The message will be ignored."
EDIT: Never$$anonymous$$d, I fixed it. Thanks for the help!
Your answer
![](https://koobas.hobune.stream/wayback/20220613165322im_/https://answers.unity.com/themes/thub/images/avi.jpg)