- Home /
Question by
memebrane101 · Oct 08, 2021 at 12:58 AM ·
2d-platformerjumping2d sprites2d animation
Jump Animation 2D problems
I'm new to coding and I'm using Brackeys tutorial and code for 2d player movement and animation. I have all the animations in but I took out the crouch animation in the code and sprites. It's just the jump animation that's not working. I have to double-tap the spacebar to get the jump animation to hold until I touch the ground. If I don't double-tap, then it flashes the jump animation for a frame then sets IsJumping back to false. Otherwise, everything else works out.
Here are the videos
https://www.youtube.com/watch?v=hkaysu1Z-N8
https://www.youtube.com/watch?v=dwcT-Dch0bA!
Here's the code: credit to Brackeys
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}
}
public void OnLanding()
{
animator.SetBool("IsJumping", false);
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, jump);
jump = false;
}
}
note: I followed Brackeys' instructions for the transitions and not to transition to self and all the conditions.
animation-map.png
(28.4 kB)
Comment