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/
thank u a lot
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
How does that player animation is triggred when moves left and right
thank's your video is very great for my game
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;
}
}
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.
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
It just plays the run animation, it doesn’t play the idle. I followed everything.
it works fine but when I play the Flip function that you did on the double jump video, doesn’t work
I love that art style, so cartoony, i love it
You are awesome!!!
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 :/
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.
With animations, you can show the player, how to play this game.
takeOF lol
thank you i can now move to 2d game making
when i do jump it doesn't respond that fast. and when i make the groundRadius higher it can jump in air.
i can't move my character please help me noa
My character won’t move after doing the animation! What do i do? Btw your videos are extremely helpful 😃
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.
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?
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?
Ahhh really love your works so cute ım happy to found your channel
idk why but u sound like a fortnite scammer lol
What code are you using for the movement
Hey, how do make the plants bend when the player is passing by? btw thanks for the tutorial!
i can't move my character and did the exact same thing
You made me understand in 15 mins what I couldn't wrap my head around for over 15 weeks… Really great tutorial!
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
Awesome video, man!
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.
The code isn't working for me. Could you make an updated version?
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 🙂
Thank you soooo much, love the videos!!!
Great video! btw your art and animation skills are amazing!
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
how to make 2D game animations:
step 1. learn to draw
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
You have saved my game I would not live without you and brackeys thank you