I’m having a problem with my animations

Updated on March 7, 2018 in  [R] 2D Graphics
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
5 on March 6, 2018

So I’m building a running game. As of right now his functions are jumping and running. I’m having a bug problem after lands from a jump sometimes gets stuck and can’t jump again . Can someone help me fix this error

  • Liked by
Reply
4 on March 6, 2018

We can’t help you with little information. Please let us know what happen in your scene. At least share screenshot from the scene or piece of code whatever you using.

on March 7, 2018

public float moveSpeed;
private float moveSpeedStore;
public float speedMultiplier;

 

public float jumpForce;

public float jumpTime;
private float jumpTimeCounter;

private bool stoppedJumping;
private bool canDoubleJump;

private Rigidbody2D myRigidbody;

public bool grounded;
public LayerMask whatIsGround;
public Transform groundCheck;
public float groundCheckRadius;

//private Collider2D myCollider;

private Animator myAnimator;

public GameManager theGameManager;

// Use this for initialization
void Start () {
myRigidbody = GetComponent<Rigidbody2D>();

//myCollider = GetComponent<Collider2D>();

myAnimator = GetComponent<Animator>();

jumpTimeCounter = jumpTime;

 

moveSpeedStore = moveSpeed;

stoppedJumping = true;

}

// Update is called once per frame
void Update() {

 

grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);

}

myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);

if ((Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) && !stoppedJumping)
{
if (grounded)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
stoppedJumping = false;

}

if(!grounded && canDoubleJump)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
jumpTimeCounter = jumpTime;
stoppedJumping = false;
canDoubleJump = false;
}

}

if (Input.GetKey (KeyCode.Space) || Input.GetMouseButton(0))
{
if(jumpTimeCounter > 0)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
jumpTimeCounter -= Time.deltaTime;
}
}

if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
{
jumpTimeCounter = 0;
stoppedJumping = true;
}

if (grounded)
{
jumpTimeCounter = jumpTime;
canDoubleJump = true;
}
myAnimator.SetFloat(“Speed”, myRigidbody.velocity.x);
myAnimator.SetBool(“Grounded”, grounded);

}

on March 7, 2018

 

https://ibb.co/gzQ0Xn when he runs

on March 7, 2018

https://ibb.co/kO6FXn

and gets stuck here

on March 7, 2018

Imo the problem is animation transitions not working correctly or grounded value does not change after first time.
Put debug.log and check the grounded. If it’s changing correctly you should review animation transitions.
P.s: All this is my opinions.

Show more replies
  • Liked by
Reply
Cancel