Example #1
0
    public override BehaviourSM.StateResponse Update(AIController controller)
    {
        Vector3 lookDirection = controller.target != null? controller.target.transform.position - controller.transform.position : controller.transform.forward;
        lookDirection.Normalize();

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

        if(isBursting) {
            controller.SetCanMove(false);
        }
        else {
            controller.SetCanMove(true);
        }

        // Update the current weapon
        if(controller.MechComponent != null && controller.MechComponent.leftWeapon != null) {
            controller.MechComponent.leftWeapon.UpdateAIAttackState(controller);
        }

        bool hasLos = controller.HasLOSTarget();
        if(hasLos) {
            lastSawTargetTime = Time.time;
            lastKnownTargetPos = controller.target.transform.position;

            // move to new shooting position at random intervals
            if(Time.time - lastMoveTime > currentMoveInterval) {
                lastMoveTime = Time.time;
                currentMoveInterval = Random.Range(minMoveInterval, maxMoveInterval);

                float engagementRange = controller.GetAttackRange();

                // the ideal location is some distance away from target, slightly random direction offset though
                Vector3 offsetDirection = (lookDirection + (Vector3)Random.insideUnitCircle).normalized;
                Vector3 shootingPosition = controller.target.transform.position - offsetDirection * engagementRange;

                controller.SetMovetoTarget(shootingPosition);
            }
        }
        else {
            // If its run out of LOS, move towards the last known position of the target
            if(controller.target != null) {
                controller.SetMovetoTarget(controller.target.transform.position);
            }
        }

        // Handle firing at target
        AttackTarget(controller);

        // TRANSITIONS:
        // give up looking for target, go to previous state
        if(!hasLos && Time.time - lastSawTargetTime > attentionSpan ||controller.target == null) {
            controller.InterruptPath();
            return new BehaviourSM.StateResponse(BehaviourSM.TransitionMode.PopPrevious);
        }

        return new BehaviourSM.StateResponse(BehaviourSM.TransitionMode.NoChange);
    }
Example #2
0
    public override BehaviourSM.StateResponse Update(AIController controller)
    {
        Vector3 targetLoc = controller.target.transform.position;
        bool hasLos = controller.HasLOSTarget();
        if(hasLos) {
            controller.SetMovetoTarget(targetLoc);
        }

        // In range to explode
        if((targetLoc - controller.transform.position).magnitude < suicideRadius) {
            controller.CommitSuicide();
        }

        return new BehaviourSM.StateResponse(BehaviourSM.TransitionMode.NoChange);
    }
Example #3
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);
    }
Example #4
0
    public override void UpdateAIAttackState(AIController controller)
    {
        base.UpdateAIAttackState(controller);
        if(!controller.isTrackingTarget) {
            controller.aiLaserSight.enabled = false;
        }
        else {
            controller.aiLaserSight.enabled = true;
        }

        if(!CanRefire() || !controller.HasLOSTarget()) {
            controller.aiLaserSight.enabled = false;
        }

        controller.aiLaserSight.SetPosition(0, firePoint.position);
        controller.aiLaserSight.SetPosition(1, controller.target.transform.position);

        const float maxSightWidth = 1.0f;
        const float minSightWidth = 0.1f;

        float sightWidth = Mathf.Lerp(maxSightWidth, minSightWidth, ai_AquireTargetPct);
        controller.aiLaserSight.SetWidth(sightWidth, sightWidth);
    }