- Home /
Jump Delay Animation Solution
I I've been trying to implement a sort of "PreJump" animation for my jump animation. I have 3 states, "PreJump", "MidJump", and "Post Jump". I'm using the algorithm and variables from one of the tutorial "2D Character Controller". I've tried SetTrigger, Animation.Play, as well as switching up the "void update" module. Ideas anyone?
using UnityEngine; using System.Collections;
public class PlayerControllerScript : MonoBehaviour { public float maxSpeed = 10; bool facingRight = true; Animator anim;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpForce = 700f;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void FixedUpdate()
{
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
anim.SetBool ("Ground", grounded);
anim.SetFloat ("vSpeed", GetComponent<Rigidbody2D>().velocity.y);
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move));
GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Update()
{
if (grounded && Input.GetKeyDown (KeyCode.Space))
{
anim.SetBool ("Ground", false);
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Your answer
Follow this Question
Related Questions
Rotate an animated gameobject (2D) 1 Answer
How to fix/ameliorate jittery 2D animations, that are created using the sprite editor? 0 Answers
How to I create sudden movements using Unity's animator? 0 Answers
Where could I start with making a level editor where you can create your own terrain in Unity 2D? 0 Answers
How to flip hitboxes if my 2D Sprite is Flipped in AnimationsEditor ? [Unity2D] 1 Answer