Question by
Queee · Feb 15, 2017 at 03:14 AM ·
animationscripting problemscriptingbasicsparametersblend tree
How do I make a x move and y move parameter
Hey Im making a 2d top down game and i am trying to set up the animations. I want to make a parameter that shows the x movement right is 1 and left is -1 and the y move right is 1 left is - 1. I want to use these in a blend tree. I do not know if there is any other way to do this but i have a feeling this will work.
Heres 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 x_move;
public float y_move;
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));
}
{
if (Input.GetKeyDown(KeyCode.W))
anim.SetTrigger("Moving");
if (Input.GetKeyDown(KeyCode.A))
anim.SetTrigger("Moving");
if (Input.GetKeyDown(KeyCode.S))
anim.SetTrigger("Moving");
if (Input.GetKeyDown(KeyCode.D))
anim.SetTrigger("Moving");
}
float velocity = Mathf.Abs(new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).magnitude);
anim.SetFloat("speed", velocity);
float curDirection = anim.GetFloat("Direction");
{
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How do I find the direction I'm going for my blend tree? 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
Animating Through Blend Tree - Method not implemented? 0 Answers
animation scirpting 1 Answer