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. (link because I can't have anymore attatchments)
http:// orig15(.) deviantart(.)net /fa04/f/2016/354/8/3/unity_movement_chart_by_blueneonkid-das9e8a.png
(Remove the spaces and parenthesis (yeah, it's a bit Youtube 2009, but what can I do? I'm new here.)
The character has a running animation for every direction, including the diagonal directions. Here is my animator controller set up:
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"));
}
}
Note: Here, I tried combining the axes inputs.
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 ("isDiagonalLeft", false);
}
}
}
Here, I tried using a Boolean to trigger the animation
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?
EDIT: I tried a solution one guy on Unity Answers suggested, which was using a 2D Freeform Directional chart. Here's my setup for that (Link becaus I can't have any more attatchments):
http:// img04(.)deviantart(.)net/39b5/i/2016/354/9/b/zanimator_setup_2_by_blueneonkid-dasaome.png
(again, remove the spaces and parenthesis)
It still doesn't play the diagonal run animation whenever I hold two directional keys down.
I set the Diagonal Left animation to -1, 1 and the Diagonal Right animation to 1,1
(If anyone's wondering why I'm trying to achieve such an archaic way of movement, I'm trying to emulate the locomotion style of Megaman Legends 2, an Action RPG released in 2000 for the PS1.
Unlike modern Action RPGs where you can move 360 degrees, MML2 had 8 directions of movement. Kind of like Ocarina of Time.)
Input.GetAxisRaw
to interpret input without smoothing, giving you digital input if you use keys, instead of analog. \$\endgroup\$