Пример #1
0
    void Update()
    {
        Vector3 moveVec = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        if (mainBody.transportSocket.transport != null)
        {
            mainBody.transportSocket.transport.nodeObject.Drive(moveVec);
        }

        playerCamera.transform.position = mainBody.transform.position + cameraOffset;
        playerCamera.transform.rotation = Quaternion.Euler(cameraAngle);

        if ((Input.GetJoystickNames().Length == 0) || !Settings.bUsingController)
        {
            gunAimVec = Input.mousePosition - playerCamera.WorldToScreenPoint(mainBody.transform.position);
        }
        else
        {
            gunAimVec = new Vector3(Input.GetAxis("RightStick-X"), Input.GetAxis("RightStick-Y"), 0);
        }


        gunAimVec.Set(gunAimVec.x, 0, gunAimVec.y);
        if (gunAimVec.magnitude > 0.1)
        {
            mainBody.transform.rotation = Quaternion.Euler(0, Quaternion.FromToRotation(new Vector3(0, 0, 1), gunAimVec).eulerAngles.y, 0);
        }
        a.SetFloat("Speed", moveVec.magnitude * speed);

        if ((Input.GetJoystickNames().Length == 0) || !Settings.bUsingController)
        {
            if (Input.GetButtonDown("Fire1"))
            {
                mainBody.StartFirePrimary();
            }

            if (Input.GetButtonUp("Fire1"))
            {
                mainBody.CeaseFirePrimary();
            }
        }
        else
        {
            if (gunAimVec.magnitude > 0.5f && !mainBody.isFiring)
            {
                mainBody.StartFirePrimary();
            }
            if (gunAimVec.magnitude < 0.1f && mainBody.isFiring)
            {
                mainBody.CeaseFirePrimary();
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        float playerDistance = (sp.lm.playerInstance.transform.position - transform.position).magnitude;

        if (playerDistance < aggroRadius)
        {
            aggro += aggroGainRate * Time.deltaTime;
        }
        else
        {
            aggro -= aggroDecayRate * Time.deltaTime;
            aggro  = Mathf.Max(aggro, 0);
        }

        if (aggro > aggroThreshold)
        {
            if (dmg.health / dmg.maxHealth < fleeThreshold)
            {
                state = EnemyAIState.Flee;
            }
            else
            {
                state = EnemyAIState.Pursue;
            }
            this.transform.rotation = Quaternion.Euler(new Vector3(0, Quaternion.LookRotation((sp.lm.playerInstance.transform.position - transform.position).normalized).eulerAngles.y, 0));
            if (bs.isFiring && Random.value < (timeInState / triggerInertia) / (1 + (triggerHappiness * aggro)))
            {
                timeInState = 0.0f;
                bs.CeaseFirePrimary();
            }
            if (!bs.isFiring && Random.value < (triggerHappiness * aggro * timeInState) / triggerInertia)
            {
                timeInState = 0.0f;
                bs.StartFirePrimary();
            }
            timeInState += Time.deltaTime;
        }
        else
        {
            bs.CeaseFirePrimary();
            state       = EnemyAIState.Wander;
            timeInState = 0.0f;
        }

        switch (state)
        {
        case EnemyAIState.Wander:
            if (wanderTime <= 0)
            {
                Vector3 r = Random.onUnitSphere;
                r.y        = 0;
                wanderDest = transform.position + r * wanderDistance;
                wanderTime = Random.value * wanderStagnation;
            }

            break;

        case EnemyAIState.Pursue:
            if (wanderTime <= 0)
            {
                Vector3 r = Random.onUnitSphere;
                r.y        = 0;
                wanderDest = transform.position + (r + ((sp.lm.playerInstance.transform.position - this.transform.position).normalized * aggro)).normalized * wanderDistance;
                wanderTime = Random.value * wanderStagnation / (aggro + 0.1f);
            }

            break;

        case EnemyAIState.Flee:
            if (wanderTime <= 0)
            {
                Vector3 r = Random.onUnitSphere;
                r.y        = 0;
                wanderDest = transform.position + (r + ((this.transform.position - sp.lm.playerInstance.transform.position).normalized * aggro)).normalized * wanderDistance;
                wanderTime = Random.value * wanderStagnation / (aggro + 0.1f);
            }
            break;

        default:
            break;
        }
        if ((wanderDest - transform.position).magnitude >= 2.6)
        {
            if (bs.transportSocket.transport != null)
            {
                bs.transportSocket.transport.nodeObject.Drive((wanderDest - transform.position).normalized);
            }
        }
        wanderTime -= Time.deltaTime;
    }