Question by
jetstyler1199 · Apr 27, 2020 at 01:24 AM ·
animationprogrammingfalling
how to make a fall animation play when walking of an edge and a landing animation
So im trying make it so that when the player walks of a platform it would play a falling animation and play the land animation once they land, for the most part the falling animation works after the jump animation,so i just need it to know how to make this work. do i need to make another script? could i get some help with this please.
here's the code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayersController2D : MonoBehaviour
{
Animator animator;
Rigidbody2D rb2d;
SpriteRenderer spriteRenderer;
bool isGrounded;
public float jumpForce;
public Transform groundcheck;
public float checkRadius;
public LayerMask whatIsGround;
private float jumpTimeCounter;
public float jumpTime;
private bool isJumping;
[SerializeField]
Transform groundCheckR;
[SerializeField]
Transform groundCheckL;
[SerializeField]
Transform groundCheckC;
[SerializeField]
Transform groundCheckCR;
[SerializeField]
Transform groundCheckCL;
[SerializeField]
private float runspeed =1.5f;
[SerializeField]
private float jumpspeed = 5f;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
rb2d = GetComponent<Rigidbody2D>();
spriteRenderer = GetComponent<SpriteRenderer>();
}
private void FixedUpdate()
{
if((Physics2D.Linecast(transform.position, groundCheckR.position, 1 << LayerMask.NameToLayer("Ground"))) ||
(Physics2D.Linecast(transform.position, groundCheckL.position, 1 << LayerMask.NameToLayer("Ground"))) ||
(Physics2D.Linecast(transform.position, groundCheckC.position, 1 << LayerMask.NameToLayer("Ground"))) ||
(Physics2D.Linecast(transform.position, groundCheckCL.position, 1 << LayerMask.NameToLayer("Ground"))) ||
(Physics2D.Linecast(transform.position, groundCheckCR.position, 1 << LayerMask.NameToLayer("Ground"))))
{
Debug.Log("on Ground");
isGrounded = true;
}
else
{
Debug.Log("not on Ground");
isGrounded = false;
}
if (Input.GetKey("d") || Input.GetKey("right"))
{
rb2d.velocity = new Vector2(runspeed, rb2d.velocity.y);
if(isGrounded)
animator.Play("Run Animation");
spriteRenderer.flipX = false;
}
else if (Input.GetKey("a") || Input.GetKey("left"))
{
rb2d.velocity = new Vector2(-runspeed, rb2d.velocity.y);
if (isGrounded)
animator.Play("Run Animation");
spriteRenderer.flipX = true;
}
else
{
if (isGrounded)
animator.Play("Idle Animation");
rb2d.velocity = new Vector2(0, rb2d.velocity.y);
}
if (isGrounded == true && Input.GetKey("space"))
{
rb2d.velocity = new Vector2(rb2d.velocity.x,jumpspeed);
animator.Play("Jump Animation");
isJumping = true;
jumpTimeCounter = jumpTime;
rb2d.velocity = Vector2.up * jumpForce;
}
}
}
here's my animator panel
61cdbf68f6bd7372ed3be79d9fbd76bb-1.png
(33.6 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612232552im_/https://answers.unity.com/themes/thub/images/avi.jpg)