Exemple #1
0
    void Update()
    {
        attack = (transform.position - attackTarget.position).magnitude < attackRadius;
        if (attack)
        {
            if (attackWalk == null || pathTimer.IsTimerDone())
            {
                pathfindingInput.from   = transform.position;
                pathfindingInput.target = attackTarget.position;

                NavMeshPath navPath = new NavMeshPath();
                navMeshAgent.CalculatePath(pathfindingInput.target, navPath);

                attackPath.Clear();
                foreach (var c in navPath.corners)
                {
                    attackPath.Add(c);
                }
                attackPath.Reverse();


                //attackPath = PathFinding.FindPath(pathfindingInput);
                attackWalk = new Walk(attackPath, transform, nearDistance);
                pathTimer.Restart();
            }
        }

        var target = SelectTarget();

        if (target != Vector2.zero)
        {
            motorState          = motor.UpdateMotorVelocity(transform, SelectTarget(), motorState.velocity);
            transform.position += (motorState.velocity + m_flockingDelta) * Time.deltaTime;
            if (motor.AbsoluteRotation())
            {
                transform.rotation = motorState.rotation;
            }
            else
            {
                transform.rotation *= motorState.rotation;
            }
        }
    }