protected virtual void FixedUpdate() { if (IsDead) { return; } steering = Vector3.zero; aceleration = Vector3.zero; if (!IsReachedTarget) { if (TargetEntity != null) { steering += steerBh.Seek(this, TargetEntity.Position) * SeekingWeight; } else { steering += steerBh.Seek(this, target) * SeekingWeight; } if (OnObsAvoidance) { neighbours = Owner.GetNeighbours(this); steering += flockBh.Separation(this, neighbours) * Separation; steering += flockBh.Alignment(this, neighbours) * Alignment; steering += flockBh.Cohesion(this, neighbours) * Cohesion; } } else { DetectEnemy(); } // obstacle avoidance test if (AgentRigid.velocity.sqrMagnitude > MinVelocity) { DetectBoxLenght = avoidanceBh.CalculateDetectBoxLenght(this); obstacles = StoredManager.GetObstacle(this); steering += avoidanceBh.GetObsAvoidanceForce(this, obstacles) * AvoidanceWeight; } aceleration = steering / AgentRigid.mass; Vector3 tempVel = TruncateVel(AgentRigid.velocity + aceleration); if (!float.IsNaN(tempVel.x) && !float.IsNaN(tempVel.y) && !float.IsNaN(tempVel.z)) { AgentRigid.velocity = tempVel; } RotateAgent(); if (!IsReachedTarget) { IsReachedTarget = CheckReachedTarget(); if (IsReachedTarget) { AgentRigid.velocity = Vector3.zero; } } }