how would I get my character to do free form motion(running in any direction with out a straifing animation) with a walk and a run animation using mecanim
here are some examples
videos:
on the above like go to seconds 12 and watch it until you see it hit 19 seconds the character runs forwards, backwards, left, and right with the same running animation with no strafing animations what so ever
link #2:
the above video is what I wan’t to achieve a walking and running animation that has no strafing and you can run in any direction how do you script it here’s what i’ve scripted so far
script
usingUnityEngine;
usingSystem.Collections;
publicclassPlayerMovement : MonoBehaviour {
TransformmainCamera;
privateAnimatoranim;
privatefloatvertical;
privatefloathorizontal;
//Usethisforinitialization
voidStart () {
anim = GetComponent <Animator> ();
}
//Updateiscalledonceperframe
voidUpdate ()
{
}
}
The script is the smallest part of this by far. All you’re going to do in the script is to set two floats, representing your X and Z (or Y) velocity:
void Update() {
float xVelocity = Input.GetAxis("Horizontal") * moveSpeed; //or however you are calculating movement
float zVelocity = Input.GetAxis("Vertical") * moveSpeed;
transform.position += new Vector3(xVelocity, 0f, zVelocity) * Time.deltaTime
anim.SetFloat("xVelocity", xVelocity);
anim.SetFloat("zVelocity", zVelocity);
}
In terms of script, that’s all there is to it. In the animator controller editor, add 2 float parameters with names matching the names you pass into those function. Then create a 2D Blend Tree (Create from New Blend Tree, then in the inspector, choose 2D Freeform Cartesian). Add the 2 float parameters as the X and Y of the blend tree. At that point, you just place each animation in the correct X and Y position to match.
Sidenote: if you can get/make animations that have root motion (google it), you should use that and you don’t have to move the character in script.
Thank you for your replies ill try the first one in the script tomorrow this will surely help me get started with megaman zero fan game thank you
Oh yeah forgot a couple more things how would I add a jump and actions such as block and done
says I have an error un expected symbol ‘=’
it now says that move speed doesn’t exist