I have bought an asset in the asset store which worked great till Unity 4.6 But since I changed to 5 my animals start to float over the ground after some seconds and then after a while even rotating around the y axis. I wrote the developer but so far I got no answer since a longer time. So I guess I have to fix that by myself but I don't see the problem. The animal has a character controler, an animation and a FSM. The problem seems to starts when the animal changed from the idle state to the moving state. In Unity 4.6 everything was fine Code (CSharp): public class FSM : MonoBehaviour { public float gravity = 100.0f;//gravity affecting character private enum State {//enumeration of states Idle,//idling state Search,//searching state BackHome, } private float speed = 6.0f;//character's movement speed private float timer = 1f;//time we're going to spend searching player private float timeCheck;// private float idlingTime = 5f;//time we're going to spend for idling public float idleTimeReset = 5f;//idling time reseter private bool alive= true;//cow is still alive private bool idling; public bool iamACow; private State state; private CharacterController charContrl;//character controller private Vector3 target;//coordinates of the target private Vector3 homePosition; private Vector3 moveDirection;//movement direction private Vector3 lookDirection;//look direction // Use this for initialization void Awake() { homePosition = this.transform.position; } void Start () { ///////CACHING VARIABLES timeCheck = Time.time; charContrl = GetComponent<CharacterController>(); state = FSM.State.Search;//starting state set to idle StartCoroutine("FSMach");//start our state machine } private IEnumerator FSMach(){ while(alive){//if character is still alive switch(state){ case State.Search: Search(); break; case State.Idle: Idle(); break; case State.BackHome: BackHome(); break; } yield return null; } } private void Search(){//search state speed = 2f; //current movement speed Moving();//run movement function if((homePosition - this.transform.position).magnitude >10f){//if we're far from home lets get back there idling = false; state = FSM.State.BackHome; } if(Time.time - timeCheck > Random.Range(1, 5)){ //if 5 sec. passed Vector2 newPosition =(Random.insideUnitSphere * 10f); //calculating random position inside UnitSphere with radius 15 target = new Vector3(newPosition.x, target.y, newPosition.y)+this.transform.position; //current target's position = random position timeCheck = Time.time;//time check equal to absolute time timer++;//increase timer by 1 } if(timer>Random.Range(1, 10)){//while timer is lesser than 5 state = FSM.State.Idle; // changing state to patrol timer = 0;//zeroing timer idling = true; } } private void Idle(){//idle state if(idling){ if (idlingTime > 0)//while idling time is greater than 0 idlingTime -= Time.deltaTime;//descrease idling time by Time.deltaTime if (idlingTime < 0) idlingTime = 0;//idling time can not be lesser than 0 if (idlingTime == 0)//when idling time become 0 { idling = false;////we're not idling anymore state = FSM.State.Search;//we're patroling idlingTime = idleTimeReset;//reset our idling timer speed = 2f;//change movement speed from 0 to 2 } } } private void BackHome(){//search state speed = 2f; //current movement speed Moving();//run movement function target = homePosition; //current target's position = random position Moving();//run movement function if((homePosition - this.transform.position).magnitude <= 1f){ state = FSM.State.Idle; // changing state to patrol idling = true; } } private void Moving(){//movement function if(!idling){//executed when we're not idling moveDirection = transform.TransformDirection(Vector3.forward);//moving forward moveDirection.y -= gravity * Time.deltaTime*10f;// applying gravity charContrl.Move(moveDirection *speed *Time.deltaTime); //moving character controller forward with speed over time lookDirection = target - this.transform.position; // calculating look direction (towards target) lookDirection.y = 0; // restricting Y axis rotation Quaternion newRot = Quaternion.LookRotation (lookDirection);//rotation that looks along forward with the the head upwards along upwards this.transform.rotation = Quaternion.Slerp(transform.rotation, newRot, Time.deltaTime * 3); //smooth linear interpolation from our current rotation to new rotation } } void Update () { if(this.GetComponent<Animation>().enabled){//check if animation of character is enabled if(speed == 2){//if character's speed is 2 GetComponent<Animation>().CrossFade("walk");// play walk animation if(iamACow){ GetComponent<Animation>()["walk"].speed = 2f; } } if(idling){//if character's speed is 0 GetComponent<Animation>().CrossFade("eat");// play idle animation } } else{//if animation is disabled - do nothing return; } } }
you are using Animator Component on the Animals. Check if Apply Root Motion is checked if yes, disable it.
Where can I find that? I looked in the inspector and only the dog has an animator component in it. There is a root motion option. All other animals have only an animation and there I can't see that option. Can I find it somewhere else?
I looked for this root motion and found something. It's disabled. When I enabled root motion then I could see that the movement looks much different from my problem, so I guess the reason is somewhere else. I made a small video to show how my "floating" looks like. It seems as if the animals are stepping on some invisible rock or stair. I can't find a reason. http://www.3aussies.de/docs/kuehe.mp4 The Animationtype is legacy and Generation is "Store in Root (new)"
I changed .Move to .SimpleMove and now my animals stay on the ground. But I don't understand why .Move isn't working. In Unity 4.6 it was no problem
CharacterController.SimpleMove public bool SimpleMove(Vector3 speed); Description Moves the character with speed. Velocity along the y-axis is ignored. try commenting line 111 (disable it) and run .Move() Code (CSharp): moveDirection.y -= gravity * Time.deltaTime*10f;// applying gravity Code (CSharp): // moveDirection.y -= gravity * Time.deltaTime*10f;// applying gravity