- Home /
Question by
Queee · Feb 17, 2017 at 09:15 AM ·
animationscripting problemscriptingbasicsblend tree
How would I set up this blend tree for my 2d game
Hey im making a top down 2d game and im trying to set up a blend tree. The animations are walking up, left,right, and down. That means speed would not work. I dont know what would work so any help?
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
Having trouble coding an on/off toggle for an animation in script. Please help! 1 Answer
How to modify ChildMotion.position via script during runtime 1 Answer
How to make door open and close with Input.GetButtonDown? 1 Answer
Have damage done to player via colliders, only a certain amount of times? 1 Answer
Animations interupting Aim-Script 0 Answers