So i want to make enemies react to a certain fighting move say a Punch enemy reacts to a (Punch) say it kicks i want enemy to react differently to the kick. i have all the animations and i know how the animator works can someone help me with this?
If you’ve got all the animations, could you use Animator.SetTrigger()? As long as you’ve got the appropriate reaction animations sorted out - which I understand you have - all you need do is pass the corresponding trigger to the animator component (e.g., Animator.SetTrigger(“Kick”) for the kick).
SetTrigger is the way to go but need to be more specific as to when these triggers are called. If a certain button is pressed to kick and another to punch use that as conditions when the kicker/puncher is within mele range of course i.e. a trigger zone collider around the enemy that the player must be within in order for the button press code to SetTrigger. Or …put colliders on player fists and feet with tags “fist” or “feet” and when the tagged “fist” or “feet” collider hits enemy trigger collider you can use the appropriate SetTrigger. Which would be better as it would actually be more accurate whereas the first example of the player just being in mele range and using a button command could look stupid if the player is in the trigger zone but facing away from the enemy
using UnityEngine;
using System.Collections;
public class hitReactions : MonoBehaviour {
Animator anim;
void Start () {
anim = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other) {
if(other.tag == "Fist")
{
anim.SetTrigger ("punchHitReact");
if(other.tag == "Feet")
{
anim.SetTrigger ("kickHitReact");
}
}
}