So, I’ve set up a controlling script for a character of mine and here is the issue: I’m using “OnCollisionEnter/Exit” to check when to play a falling animation, landing animation and such, but whenever passing from one collider to another, the character does the landing animation even if both colliders are in contact with the character at once. How do I make it so that it checks for other colliders before setting the animation? Here is the code if it helps:`
{
Animator anim;
int jumpHash = Animator.StringToHash("jump");
int runStateHash = Animator.StringToHash("Base Layer.run");
int fightHash = Animator.StringToHash("fight");
int specfightHash = Animator.StringToHash("specfight");
int turnlHash = Animator.StringToHash("turnl");
int turnrHash = Animator.StringToHash("turnr");
int crouchHash = Animator.StringToHash("crouch");
int dropHash = Animator.StringToHash("drop");
int landingHash = Animator.StringToHash("landing");
public Animator Charanimator;
public CapsuleCollider character;
public Rigidbody rigid;
public Transform chartrans;
void Start ()
{
anim = GetComponent<Animator>();
}
void FixedUpdate ()
{
float move = Input.GetAxis ("Vertical");
anim.SetFloat ("speed", move);
AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo (0);
if (Input.GetKeyDown (KeyCode.Space) && stateInfo.fullPathHash == runStateHash) {
anim.SetTrigger (jumpHash);
}
if (Input.GetKeyDown (KeyCode.Space)) {
anim.SetTrigger (jumpHash);
}
if (Input.GetKeyDown (KeyCode.Mouse0)) {
anim.SetTrigger (fightHash);
}
if (Input.GetKeyDown (KeyCode.Mouse1)) {
anim.SetTrigger (specfightHash);
}
if (Input.GetKey (KeyCode.LeftArrow)) {
anim.SetTrigger (turnlHash);
}
if (Input.GetKey (KeyCode.RightArrow)) {
anim.SetTrigger (turnrHash);
}
if (Input.GetKey (KeyCode.C)) {
anim.SetTrigger (crouchHash);
}
if (Input.GetKey (KeyCode.LeftArrow) && stateInfo.fullPathHash == runStateHash)
{
chartrans.Rotate(Vector3.up * -50f* Time.deltaTime);
}
if (Input.GetKey (KeyCode.RightArrow) && stateInfo.fullPathHash == runStateHash)
{
chartrans.Rotate(Vector3.up * 50f* Time.deltaTime);
}
}
void OnCollisionExit (Collision col)
{
anim.SetTrigger (dropHash);
character.height = 1.52f;
character.center = Vector3.up * 1f;
}
void OnCollisionEnter (Collision col)
{
character.height = 1.84f;
character.center = Vector3.up * 0.92f;
anim.SetTrigger (landingHash);
}
}
`