I have been trying to apply some animations I made and turn it into a game character. It has been working okay except for some problems. First, the character comes in unity missing it's eyes. I ignored that then moved onto the movement of the character. When a translation happens the correct walk animation starts but the characters placement in the world just keeps snapping back to it's original position. If it helps i'll also leave the code for the movements Code (CSharp): using System.Collections; using Systems.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { Rigidbody rb; float speed = 50.0F; float rotationSpeed = 80.0F; Animator animator; void Start(){ rb = this.GetComponent<Rigidbody>(); animator = GetComponentInChildren<Animator>(); animator.SetBool("Idling", true); } // Update is called once per frame void LateUpdate () { float translation = Input.GetAxis("Vertical") * speed; float rotation = Input.GetAxis("Horizontal") * rotationSpeed; translation *= Time.deltaTime; rotation *= Time.deltaTime; Quaternion turn = Quaternion.Euler(0f,rotation,0f); rb.MoveRotation(rb.rotation * turn); animator.SetFloat("SpeedMult",translation); if(translation != 0) animator.SetBool("Idling", false); else animator.SetBool("Idling", true); if (Input.GetKeyDown ("space")) { animator.SetTrigger ("Sit"); } if (Input.GetKeyDown ("f")) { animator.SetTrigger ("Flip"); } } }
is there movement of whole dog forward in walk animation itself? if yes, it can be a rpoblem. not a code. As far as I know, the movement forward should be made completely in code, and it should not be there in walk animation file.
This one does have movement. I used the one with no root movement first but that animation freezes after one cycle and the character won't move or go back to it's idling position.
To make character animation switch from playing animation to other - is another thing. I tried using "state machines" for that, making conditions, but I didn't find that flexible enough. as for freezing animation after one cycle. Well, if you make moving forward, walking, then you should make walking function. In Update() make "if" block to check for pressing "cursor up" etc, and call the walk function. And in walk function, you should play animation. But I'ld better don't use SetBool for that. I don't find it very flexible. Instead I directly set name of Animation to "walk". And also you have to add movement along the axis "backward-forward". Something like "x = x + 1". So if you hold cursor up, dog will move forward. Even if there will be no animation, it should move forward.