private void Start() { areaPenguin = GetComponentInParent <AreaPenguin>(); baby = areaPenguin.penguimBebe; animator = GetComponent <Animator>(); rayPerception = GetComponent <RayPerception3D>(); }
private void Swim() { if (Time.fixedTime >= nextActionTime) { //Randomize speed randomizeSpeed = fishSpeed * UnityEngine.Random.Range(.5f, 1.5f); targetPosition = AreaPenguin.EscolherRandomPosicao(transform.parent.position, 100f, 260f, 2f, 13f); //ratoate toward transform.rotation = Quaternion.LookRotation(targetPosition - transform.position, Vector3.up); //Calculate the time to get there- calcular o tempo para chegar no destino float timeToGetThere = Vector3.Distance(transform.position, targetPosition) / randomizeSpeed; nextActionTime = Time.fixedTime + timeToGetThere; } else { //Make sure that the fish does not swin past target Vector3 moveVector3 = randomizeSpeed * transform.forward * Time.fixedDeltaTime; if (moveVector3.magnitude <= Vector3.Distance(transform.position, targetPosition)) { transform.position += moveVector3; } else { transform.position = targetPosition; nextActionTime = Time.fixedTime; } } }