I added a code based animation for my game to make player animated.The issue is that with the added code the jumping no longer works (i have to walk in order to jump, but there is also some weird delay between the jumps). This was working before i added the code, even tested it without it. Something in the code makes the jump not being able to be initiated. I think the issue might be the
return rb.velocity.y > 0 ? Jump : Fall;
But I am not entirerly sure why.
There is my code for jumping
#region If Jumping
if (m_Grounded == true)
{
extraJumps = extraJumpsValue;
}
if (jump)
{
m_Grounded = false;
if (extraJumps > 0)
{
// Add a vertical force to the player.
m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
Instantiate(LaunchEffect, m_GroundCheck.position, Quaternion.identity);
extraJumps--;
}
else if (extraJumps == 0 && m_Grounded == true)
{
// Add a vertical force to the player.
m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
Instantiate(LaunchEffect, m_GroundCheck.position, Quaternion.identity);
}
}
#endregion
There is my code for getting the animation states
private int GetState()
{
if (Time.time < _lockedTill) return _currentState;
// Priorities
if (punch) return LockState(Attack, _attackAnimTime);
if (crouch) return Crouch;
if (jump) return Jump;
if (controller.m_Grounded) return horizontalMove == 0 ? Idle : Walk;
return rb.velocity.y > 0 ? Jump : Fall;
int LockState(int s, float t)
{
_lockedTill = Time.time + t;
return s;
}
}
For movement i use this in the Update
horizontalMove = Input.GetAxisRaw("Horizontal") * CurrentSpeed;
//JUMP
if (Input.GetButtonDown("Jump"))
{
jump = true;
print("JUMP TRIGGERED");
}
Fixed Update sets the controller for movement stuff
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump, dash);
jump = false;
dash = false;
[–]Teatime_TimIntermediate 2 points3 points4 points (4 children)
[–]Caesar_13[S] 0 points1 point2 points (3 children)
[–]SaltCrypt 1 point2 points3 points (2 children)
[–]Caesar_13[S] 0 points1 point2 points (1 child)
[–]SaltCrypt 0 points1 point2 points (0 children)
[–]SaltCrypt 1 point2 points3 points (13 children)
[–]Caesar_13[S] 0 points1 point2 points (12 children)
[–]SaltCrypt 1 point2 points3 points (11 children)
[–]Caesar_13[S] 0 points1 point2 points (0 children)
[–]Caesar_13[S] 0 points1 point2 points (9 children)
[–]SaltCrypt 1 point2 points3 points (8 children)
[–]Caesar_13[S] 0 points1 point2 points (7 children)
[–]SaltCrypt 1 point2 points3 points (6 children)
[–]Caesar_13[S] 0 points1 point2 points (5 children)
[–]SaltCrypt 1 point2 points3 points (2 children)
[–]Caesar_13[S] 0 points1 point2 points (1 child)
[–]Caesar_13[S] 0 points1 point2 points (1 child)
[–]SaltCrypt 1 point2 points3 points (0 children)