I have a model moving using root motion. Currently, it’s moving in 4 directions; Forward, Backward, Right, and Left.
Now, I want to make the character move in 45 degrees. I made a chart to understand the axes.

The character has a running animation for every direction, including the diagonal directions. Here is my animator controller set up (image link because I can’t have any more attatchments):
I started out with trying to move diagonally left, and tried out a few scripts.
Script #1 (The simplest):
public class Zcontroller : MonoBehaviour {
private Animator myAnimator;
// Use this for initialization
void Start () {
myAnimator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
myAnimator.SetFloat ("VSpeed", Input.GetAxis ("Vertical"));
myAnimator.SetFloat ("HSpeed", Input.GetAxis ("Horizontal"));
myAnimator.SetFloat ("DiagSpeed", Input.GetAxis ("Vertical") + Input.GetAxis ("Horizontal"));
Script #2:
using UnityEngine;
using System.Collections;
public class Zcontroller : MonoBehaviour {
private Animator myAnimator;
// Use this for initialization
void Start () {
myAnimator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
myAnimator.SetFloat ("VSpeed", Input.GetAxis ("Vertical"));
myAnimator.SetFloat ("HSpeed", Input.GetAxis ("Horizontal"));
if (Input.GetAxis ("Vertical") || Input.GetAxis ("Horizontal")) {
if ((Input.GetAxis ("Vertical") < 0f) && (Input.GetAxis ("Horizontal") > 0)) {
myAnimator.SetBool ("isDiagonalLeft", true);
}
} else {
myAnimator.SetBool ("TurningLeft", false);
}
}
}
Script #3 (As an image link because I forgot to save this one and can’t add any more attachments):
Results:
Script 1 did not work, and caused the character to move diagonally only when the Down Arrow key was pressed.
Script 2 also did not work, giving me the error: “Operator ‘||’ cannot be applied to operands of type ‘float’ and ‘float’.”
Script 3 gave me some bracket errors.
What can I do to get the character to move diagonally properly?
Is there any way to combine two float values in code? If so, how?
