- Home /
This question was
closed Nov 13, 2014 at 10:42 PM by
ExtremePowers for the following reason:
The question is answered, right answer was accepted
Question by
ExtremePowers · Nov 11, 2014 at 10:09 PM ·
animationmecanimtransition
Mecanim state problem
Why doesn't this code toggle sprinting if the animator controller is in the sprint state:
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
var vert = Input.GetAxis("Vertical");
var hori = Input.GetAxis("Horizontal");
var sprinting = Input.GetButton("Sprint");
if (hori != 0 || vert != 0) {
anim.SetFloat(SpeedHash, 1);
} else {
anim.SetFloat(SpeedHash, 0);
}
anim.SetBool(SprintHash, sprinting);
anim.SetFloat(DirectionHash, hori);
moveDirection = new Vector3(hori, 0, vert);
moveDirection = transform.TransformDirection(moveDirection);
if (sprinting) {
moveDirection *= sprintSpeed;
} else {
moveDirection *= speed;
}
if (Input.GetButton("Jump")) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
The walk state requires speed to be over 0.1 and will go back to idle if it's lower than that. It will go to Run if sprint is true and go back to Idle if it's false. But for some reason, the SetBool and SetFloat's doesn't work after the state has gone into Run. The mecanim parameters aren't even getting set after the state is Run, but the program is still receiving the right input.
screenshot 2014-11-11 23.03.19.png
(7.0 kB)
Comment
Best Answer
Answer by ExtremePowers · Nov 13, 2014 at 10:42 PM
So, I figured this one out, it was because the Run blend tree didn't have any motion field added, or assigned..