Animation does weird
Hi guys,
I want to make an animation for my game, but it is not working the way I want. This is what I want: LeftAni as long as the player is touching left, RightAni as long as the player is touching right, and when the player is not touching the screen, Idle.
This is my code:
void FixedUpdate () {
var animator = gameObject.GetComponent<Animator>();
foreach (Touch touch in Input.touches) {
if (Input.GetTouch (0).phase != TouchPhase.Ended) {
if (touch.position.x < Screen.width / 2) {
PlayerRb.AddForce (-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
animator.SetTrigger ("LeftClick");
} else if (touch.position.x > Screen.width / 2) {
PlayerRb.AddForce (sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
animator.SetTrigger ("RightClick");
}
} else {
animator.SetTrigger ("NoClick");
}
}
}
With this code and Animator, my character is playing multiple animations at the same time it seems. For example: when clicking right the first time and holding my finger, it works fine (it stays in RightAni). But when I release my finger it does strange: the Idle animation is played, then back to RightAni (but it has to stay in idle). Also from LeftAni to RightAni, and from RightAni to LeftAni it is playing strangely. Any tips?
Your answer
Follow this Question
Related Questions
How can I improve this code? 1 Answer
animation scirpting 1 Answer
How to animate multiple objects in sequence? 0 Answers
Confused about animations 1 Answer
Animation not consistent 0 Answers