Hi, Im working on a melee combat system which is currently setup this way:
The weapon has a RigidBody (set to kinematic and with gravity off) and a capsule collider (set as a trigger), when the weapon’s collider hits the enemy it sends a message to apply damage.
This is working great for me and it’s most likely the way I will go about this since it’s the most realistic and precise melee method I could find.
Now Im trying to develop a shield that will block these attacks but I can’t seem to figure out the best way to do it.
The idea is that if the weapon’s collider hits the shield it wont do any damage to the character holding it, but the problem is that since this collider is a trigger it goes right trough the shield and hits the character anyways.
I realize I can probably use “Physics.IgnoreCollision” or simply disable the enemy’s collider/rigidbody so that when he’s holding the shield it doesnt do any damage, but this is not really what Im looking for, I want enemies to be able to block incoming attacks and still take damage if they are hit on the back (or anywhere other than the shield).
One possible solution Im thinking of is implementing a “bounce back” animation, so that if you hit a shield you’ll immediately bounce back thus preventing the weapon from ever hitting the enemy, but Im not sure how to call an animation on a collision event or if that would even work at all.
Here’s the code in charge of sending the damage notification:
var player : GameObject;
var AttackDamage : float = 25.0;
function Start ()
{
Physics.IgnoreCollision(collider, player.collider);
}
function OnTriggerEnter(other : Collider)
{
if(other.GetComponent(EnemyAI))
{
other.gameObject.SendMessageUpwards("ApplyDammage", AttackDamage, SendMessageOptions.DontRequireReceiver);
}
}