MAKING RUN, IDLE & JUMP 2D GAME ANIMATIONS – UNITY TUTORIAL

39
1



In this game animation tutorial I show you how to make an idle, run and jump animation for a 2D platformer player character using Unity !

We’ll also learn how to make animation transitions between the character’s various states using the animator !

——————————————————————————————————–

SUPPORT ME via PATREON :

——————————————————————————————————–

GAME ANIMATION BASICS :

PLATFORMER CONTROLLER :

ANIMATION TRANSITIONS :

——————————————————————————————————–

FOLLOW ME on TWITTER :

JOIN the BTP DISCORD SERVER :

Nguồn: https://spirtavert.com/

Xem thêm bài viết khác: https://spirtavert.com/game/

39 COMMENTS

  1. Idk why but when i add animations my character is not able to jump or move….Animations are getting played, but the player is stuck…soemone please help

  2. If y hold down Jump key and right arrow, when it lands is stuck in the
    jumping pose, even if the character is walking. after release it goes
    into idle and then everything works fine. help.Here is the code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour {
    public float speed;
    public float jumpForce;
    private float moveInput;
    public Animator animator;

    private Rigidbody2D rb;
    private bool facingRight = true;
    private bool isGrounded;
    public Transform groundCheck;
    public float checkRadius;
    public LayerMask whatIsGround;
    private int extraJumps;
    public int extraJumpsValue;
    float timeCounter;

    void Start()
    {

    rb = GetComponent<Rigidbody2D>();
    }
    private void FixedUpdate() {
    timeCounter += -1 * Time.deltaTime;

    animator.SetFloat("Speed", Mathf.Abs(moveInput));

    isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);

    moveInput = Input.GetAxisRaw("Horizontal");
    rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
    if(facingRight == false && moveInput > 0){
    Flip();
    } else if (facingRight == true && moveInput < 0)
    Flip();
    if (timeCounter < 0) {
    timeCounter = 0.5f;
    rb.AddForce(new Vector3(0,jumpForce,0));

    }
    }
    void Update(){
    if(isGrounded == true){
    extraJumps = extraJumpsValue;
    }
    if(Input.GetKeyDown(KeyCode.UpArrow) && extraJumps > 0){
    rb.velocity = Vector2.up * jumpForce;
    extraJumps–;
    animator.SetBool("isJumping", false);
    animator.SetTrigger("isJumping");

    if (moveInput == 0){

    }
    else {
    animator.SetBool("isJumping", true);

    }
    }

    }
    void Flip(){
    facingRight = !facingRight;
    Vector3 Scaler = transform.localScale;
    Scaler.x *= -1;
    transform.localScale = Scaler;
    }
    }

  3. When i hit play, character goes to Idle when i walk it goes t the Walk animation. But when i jump is stuck on the jump animation even if on ground.

  4. Hi Noah i have a question:
    My Jump Animation don't want to work
    is it the code or am i just stupid?
    here is the code:
    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    public class CharacterController : MonoBehaviour

    {

    public float speed;

    public float Jumpforce;

    private float moveInput;

    private Rigidbody2D rb;

    private bool facingRight = true;

    private bool isGrounded;

    public Transform groundcheck;

    public float checkRadius;

    public LayerMask whatIsGround;

    private int Jumptimes;

    public int extraJump;

    public Joystick joystick;

    public Animator animator;

    // Start is called before the first frame update

    void Start()

    {

    rb = GetComponent<Rigidbody2D>();

    Jumptimes = extraJump;

    }

    // Update is for the Movement lol

    private void FixedUpdate()

    {

    isGrounded = Physics2D.OverlapCircle(groundcheck.position, checkRadius, whatIsGround);

    moveInput = joystick.Horizontal;

    if (joystick.Horizontal >= .5f)

    {

    moveInput = speed;

    }

    else if (joystick.Horizontal <= -.2f)

    {

    moveInput = -speed;

    }

    else

    {

    moveInput = 0f;

    }

    rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

    animator.SetFloat("Speed", Mathf.Abs(moveInput));

    if (facingRight == false && moveInput < 0)

    {

    Flip();

    }

    else if (facingRight == true && moveInput > 0)

    {

    Flip();

    }

    }

    // Update is called once per frame

    void Update()

    {

    float jumpingmove = joystick.Vertical;

    if (isGrounded == true)

    {

    Jumptimes = extraJump;

    animator.SetBool("IsJumping", false);

    }

    if ((jumpingmove >= .5f) && Jumptimes > 0)

    {

    rb.velocity = Vector2.up * Jumpforce;

    Jumptimes–;

    }

    if (isGrounded == false)

    {

    animator.SetBool("IsJumping", true);

    }

    else if (Input.GetKeyDown(KeyCode.UpArrow) && Jumptimes == 0 && isGrounded == true)

    {

    rb.velocity = Vector2.up * Jumpforce;

    animator.SetTrigger("takeof");

    }

    }

    void Flip()

    {

    facingRight = ! facingRight;

    Vector3 Scaler = transform.localScale;

    Scaler.x *= -1;

    transform.localScale = Scaler;

    }

    }
    Thanks for helping me if you are helping me :3
    also i like youre videos very much they're very helpfully

  5. There is still one animation missing. Falling animation. How can I transition to the falling animation when the character starts falling? Is there a way to track the characters Y velocity or something? I have been trying to figure it out unsuccesfully :/

  6. Question: I'm making a snowman animation and I want it to melt overtime how do I get that going on the same time as the other animation? Is it just as easy as making it my default animation with the 3 levels of melting? Thanks for taking the time to respond.

  7. My character won’t move after doing the animation! What do i do? Btw your videos are extremely helpful 😃

  8. Amazing Tutorial! The animation is great and I love your art style. One thing though, My player is locked into a single position. I have no clue why! Hasn't done it before I added the animations. It could just be me being dumb. I have tried our discord but didn't get a response.

  9. i downloaded an asset pack and it has a double jump animation,
    i followed blackthornprods tutorial on how to do a double jump but i have no idea how to do the animation.
    can anyone help please?

  10. someone can help me ? when i play my game with the animations he cant move but when i play without he moveme someone help me to fix this?

  11. You made me understand in 15 mins what I couldn't wrap my head around for over 15 weeks… Really great tutorial!

  12. Love your videos. You inspire us. I hope one day i will make a good one… This is what i learned (not much i know): https://play.google.com/store/apps/details?id=com.Game.VirusSmasher

  13. I'm stuck I tried this way
    if(rb.velocity.x == 0)

    {

    anime.SetBool("GroundedNow", false);

    }

    else

    {

    anime.SetBool("GroundedNow", true);

    }
    and i did this using float which is moveSpeed in the Animator channel.

    anime.SetFloat("moveSpeed", Mathf.Abs(rb.velocity.x));

    however both times the animation keeps looping from idle to run animation, any help will be very helpful cheers.

  14. i am planing to star a game dev channel so can anyone give some advise please and black thorn prod if you are reading this it would be awesome if you could give me some advise 🙂

  15. hey i know this video was from a year ago but i keep getting this error saying the name "moveinput" does not exist in the current context, any solutions would help

  16. when I do the animation my guy won’t move and when I turn on apply root motion my guy just floats up but he can still move

LEAVE A REPLY

Please enter your comment!
Please enter your name here