- Home /
Hit/React Animation
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?
Answer by GeorgeCH · Mar 28, 2017 at 01:30 PM
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).
Answer by shadowpuppet · Mar 28, 2017 at 07:59 PM
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");
}
}
}
Your answer
Follow this Question
Related Questions
Left/Right movement 2D game,Why is this code to make my character move left/right not working? 0 Answers
2D Animation workflow 0 Answers
so I'm trying to make a 2D platform but the first animation i make is the only one that registers 0 Answers
Having some stuck issues on the 2D infinite runner 0 Answers
Switch Players during play 2 Answers