Пример #1
0
    public override BehaviourSM.StateResponse Update(AIController controller)
    {
        const float minPatrolDist = 2.0f;

        if(Time.time - lastLooktime > thisLookInterval) {
            lookDirection = Random.insideUnitCircle;
            thisLookInterval = Random.Range(minWaitInterval, maxWaitInterval);
            lastLooktime = Time.time;
        }

        // If the controller has a source spawn, then check if there any patrol points associated with it to follow
        if(controller.SourceSpawn != null && controller.SourceSpawn.patrolPoints.Count > 0) {
            float distToPoint = (controller.transform.position - controller.SourceSpawn.patrolPoints[patrolIdx].position).magnitude;

            if(distToPoint < minPatrolDist) {
                patrolIdx += 1;
                if(patrolIdx >= controller.SourceSpawn.patrolPoints.Count) {
                    patrolIdx = 0;
                }
            }

            controller.SetMovetoTarget(controller.SourceSpawn.patrolPoints[patrolIdx].position);
        }
        else {
            controller.SetMovetoTarget(controller.transform.position);
        }

        // lerp towards teh current look direction
        Vector3 currentFacing = controller.headTransform.up;
        controller.headTransform.up = Vector3.RotateTowards(currentFacing, lookDirection, lookSpeed * Time.deltaTime, 0.0f);

        // TRANSITIONS:
        if(controller.HasLOSTarget()) {
            controller.OnAquireTarget();
            return new BehaviourSM.StateResponse(BehaviourSM.TransitionMode.PushCurrent, new Behaviour_Attack());
        }

        return new BehaviourSM.StateResponse(BehaviourSM.TransitionMode.NoChange);
    }
Пример #2
0
    private bool CanShootTarget(AIController controller)
    {
        // otherwise, check that there are no other mechs in the way
        Vector3 fireOrigin = GetWeaponOrigin(controller);

        // Some enemies do not shoot when they are not visible on screen
        if(controller.doesntShootOffScreen &&
           !WorldManager.instance.ObjectOnScreen(controller.gameObject)) {
            return false;
        }

        Vector3 toTarget = controller.target.transform.position - fireOrigin;
        float arcToTarget = Vector3.Dot(controller.headTransform.up, toTarget.normalized);

        // constrain the shooting to within an arc
        if(arcToTarget < maxFireArc || toTarget.magnitude > controller.GetAttackRange()) {
            return false;
        }

        if(!controller.CheckLOSFrom(fireOrigin, controller.target.transform.position, 100.0f)) {
            controller.OnLostSightOfTarget();
            return false;
        }
        else if(!controller.isTrackingTarget) {
            controller.OnAquireTarget();
        }

        // allow the weapon to decide if it can shoot yet, or if it is doing something
        if(controller.MechComponent != null && controller.MechComponent.leftWeapon != null &&
           !controller.MechComponent.leftWeapon.AI_AllowFire(controller)) {
               return false;
        }

        return true;
    }