Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (playerTrans == null)
        {
            FindPlayer();
        }
        else
        {
            var dis = Vector3.Distance(transform.position, playerTrans.position);
            if (dis <= attractRange)
            {
                var dir = playerTrans.position - transform.position;
                dir = dir.normalized;
                var moveSpeedMod = AI_StaticFunctions.LogisticFunction((attractRange - dis) / attractRange);
                dir *= moveSpeedMod * moveSpeed;

                transform.position += dir * Time.deltaTime;
            } //player is close enough to effect resource
        }     //apply attraction
    }
Пример #2
0
    // Update is called once per frame
    protected virtual void Update()
    {
        if (!offline)
        {
            if (reloadCurrent > 0f && ammoCurrent == 0)
            {
                reloadCurrent -= Time.deltaTime;
                if (reloadCurrent <= 0f)
                {
                    reloadCurrent = reloadMax; ammoCurrent = ammoMax;
                }
            }
            var target = AquireTarget();
            if (target != null)
            {
                var dir = target.transform.position - transform.position;
                Debug.DrawRay(transform.position, dir, Color.blue);
                //dir = dir.normalized;
                if (Physics.Raycast(transform.position, dir, out RaycastHit hit, turretRange, -5, QueryTriggerInteraction.Ignore))
                {
                    //Debug.Log(hit.transform.gameObject);
                    var parentTrans = hit.transform;
                    while (parentTrans.parent != null)
                    {
                        parentTrans = parentTrans.parent;
                    }
                    var parentObj = parentTrans.gameObject;

                    var health = parentObj.GetComponentInChildren <AMS_Health_Management>();
                    if (health == target)
                    {
                        //Debug.Log("health == target");
                        if (leading || cheatLeading)
                        {
                            //find the highest parent transform
                            var aimPoint = target.transform;
                            while (aimPoint.parent != null)
                            {
                                aimPoint = aimPoint.parent;
                            }

                            var charControl = aimPoint.gameObject.GetComponentInChildren <CharacterController>();
                            if (charControl != null)
                            {
                                var pos = AI_StaticFunctions.LeadTargetPosition(transform.position, Vector3.zero, bulletSpeed, charControl.transform.position, charControl.velocity);
                                dir = pos - transform.position;
                            }
                            else
                            {
                                var agent = aimPoint.gameObject.GetComponentInChildren <NavMeshAgent>();
                                if (agent != null)
                                {
                                    var pos = AI_StaticFunctions.LeadTargetPosition(transform.position, Vector3.zero, bulletSpeed, agent.transform.position, agent.velocity);
                                    dir = pos - transform.position;
                                }
                            }
                            leading = false;
                        }

                        var rotationSpeed = (turretCurrentRotationSpeed + turretRotationBuff);
                        turretRotationBuff = 0f;
                        rotationSpeed     *= Time.deltaTime;
                        var targetRotation = Quaternion.LookRotation(dir);
                        transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed);

                        if (Vector3.Angle(transform.forward, dir) < deadZone)
                        {
                            shotTimerCurrent -= Time.deltaTime;
                            if (shotTimerCurrent <= 0)
                            {
                                shotTimerCurrent    = shotCurrentTimerMax;
                                shotCurrentTimerMax = shotBaseTimerMax;
                                ShootBullet(dir);
                            }
                        }
                    }
                    //else { Debug.Log("whatever was hit didn't have a health"); }
                }
            }
        }

        if (partTimer > 0f)
        {
            partTimer -= Time.deltaTime;
            SwitchParticles(true);
        }
        else
        {
            partTimer = 0f;
            SwitchParticles(false);
        }
    }