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.
Ah, alright. I made the sword's collider a trigger, and changed the code to onTriggerEnter instead, but previously I had it set up as
– JasozzonCollisionEnter (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: Nevermind, I fixed it. Thanks for the help!