How do I find the direction I'm going for my blend tree?
Hey I'm making a 2d top down game and I am trying to set up a blend tree. This is my first time setting up a blend tree so I don't really know what I'm doing. I want it to be like when I go up the walking up animation plays and when I go down the walking down animation plays. I think you can use the direction of where you are walking to do that but as I said I don't know what I'm doing. So I would like to know how to find the direction I am going in and/how to make my animation play from my blend tree when I go that direction.
Here's my code.
using UnityEngine;
using System.Collections;
public class topdown : MonoBehaviour
{
public float moveSpeed;
private Animator anim;
public float velocity;
public float Direction;
public float input_x;
public float input_y;
public float speed;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < 0.5f)
{
transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
}
if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < 0.5f)
{
transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
}
float velocity = Mathf.Abs(new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).magnitude);
anim.SetFloat("speed", velocity);
float curDirection = anim.GetFloat("Direction");
{
}
}
}
Your answer
Follow this Question
Related Questions
How do I make a x move and y move parameter 0 Answers
Animations Bad Scripting | Controller Script Buggy | Collider Problem | Beginner Here! 0 Answers
Interchangeable animations in a script? 0 Answers
How can i make my enemy zombie do an animation when attacking and when he first sees the player 0 Answers
How do I make my speed be positive in any direction? 1 Answer