- Home /
issue using OverlapCircle and AnyState in Unity Animator,issue using OverlapCirlce and AnyState in Unity Animator
Hello, I have a problem with the Bounce, Jump and Landing animations. Can anyone please advise why these 3 animations are not working ? Running works, so I'm wondering why some work and some don't. I found out that it should be a problem with OverlapCircle2D which I have in my code, but I still don't know how to fix it. Please help me fix my code
 PlayerController: using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 public class PlayerController : MonoBehaviour
 {
     public float MoveSpeed;
     public float JumpForce;
     private Rigidbody2D player;
     private bool isGrounded;
 
     Rigidbody2D rb;
     bool facingRight = true;
     public Transform groundPos;
     public LayerMask whatIsGround;
     public float checkRadius;
 
     private bool isJumping;
 
     private Animator anim;
     void Start()
     {
         anim = GetComponent <Animator>();
         rb = GetComponent<Rigidbody2D>();
     }
 
     void Update()
     {
         isGrounded = Physics2D.OverlapCircle(groundPos.position, checkRadius, whatIsGround);
 
         if(isGrounded == true && Input.GetKeyDown(KeyCode.Z))
         {
             isJumping = true;
             anim.SetTrigger("takeOf");
         }
 
         if (isGrounded == true)
         {
             anim.SetBool("isJumping", false);
         }
         else
         {
             anim.SetBool("isJumping", true);
         }
 
         var move = Input.GetAxis("Horizontal");
         transform.position += new Vector3(move, 0, 0) * Time.deltaTime * MoveSpeed;
 
         if (Input.GetKeyDown(KeyCode.Space) && Mathf.Abs(rb.velocity.y) < 0.001f)
         {
             {
                 Jump();
             }
 
         }
         if (move == 0)
         {
             anim.SetBool("isRunning", false);
         }
         else
         {
             anim.SetBool("isRunning", true);
         }
 
         if (move<0 && facingRight)
         {
             flip();
         }
        else if (move>0 && !facingRight)
         {
             flip();
         }
 
     }
     private void FixedUpdate()
     {
         isGrounded = Physics2D.OverlapCircle(groundPos.position, 0.2f, whatIsGround);
     }
     void Jump()
     {
         rb.velocity = Vector2.up * JumpForce;
     }
     void flip()
     {
         facingRight = !facingRight;
         transform.Rotate(0f, 180f, 0f);
     }
 }
 ,Hello, I have a problem with the Bounce, Jump and Landing animations. Can anyone please advise why these 3 animations are not working ? Running works, so I'm wondering why some work and some don't. I found out that it should be a problem with OverlapCircle2D which I have in my code, but I still don't know how to fix it. Please help me fix my code PlayerController: using UnityEngine; using System.Collections; using System.Collections.Generic; public class PlayerController : MonoBehaviour { public float MoveSpeed; public float JumpForce; private Rigidbody2D player; private bool isGrounded;
 Rigidbody2D rb;
 bool facingRight = true;
 public Transform groundPos;
 public LayerMask whatIsGround;
 public float checkRadius;
 private bool isJumping;
 private Animator anim;
 void Start()
 {
     anim = GetComponent <Animator>();
     rb = GetComponent<Rigidbody2D>();
 }
 void Update()
 {
     isGrounded = Physics2D.OverlapCircle(groundPos.position, checkRadius, whatIsGround);
     if(isGrounded == true && Input.GetKeyDown(KeyCode.Z))
     {
         isJumping = true;
         anim.SetTrigger("takeOf");
     }
     if (isGrounded == true)
     {
         anim.SetBool("isJumping", false);
     }
     else
     {
         anim.SetBool("isJumping", true);
     }
     var move = Input.GetAxis("Horizontal");
     transform.position += new Vector3(move, 0, 0) * Time.deltaTime * MoveSpeed;
     if (Input.GetKeyDown(KeyCode.Space) && Mathf.Abs(rb.velocity.y) < 0.001f)
     {
         {
             Jump();
         }
     }
     if (move == 0)
     {
         anim.SetBool("isRunning", false);
     }
     else
     {
         anim.SetBool("isRunning", true);
     }
     if (move<0 && facingRight)
     {
         flip();
     }
    else if (move>0 && !facingRight)
     {
         flip();
     }
 }
 private void FixedUpdate()
 {
     isGrounded = Physics2D.OverlapCircle(groundPos.position, 0.2f, whatIsGround);
 }
 void Jump()
 {
     rb.velocity = Vector2.up * JumpForce;
 }
 void flip()
 {
     facingRight = !facingRight;
     transform.Rotate(0f, 180f, 0f);
 }
}`
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                