示例#1
0
    private void FixedUpdate()
    {
        if (myController.IsDisabled())
        {
            return;
        }

        steeringForce = Vector3.zero;

        changeTargetTimer -= Time.fixedDeltaTime;
        attackTimer       -= Time.fixedDeltaTime;

        // Check for a new target
        if (changeTargetTimer < 0.0f)
        {
            targetPlayer      = FindClosestPlayer();
            changeTargetTimer = changeTargetCheck;
        }

        // If we have a target player
        if (targetPlayer)
        {
            // If out of range, seek
            if ((this.transform.position - targetPlayer.transform.position).magnitude > attackDistance)
            {
                steeringForce += Seek(targetPlayer.transform.position);
                myController.SetLook(targetPlayer.transform.position - this.transform.position);
            }
            else if (attackTimer < 0.0f)
            {
                // If not charging or firing, start charging
                if (!myController.IsCharging() && !myController.IsFiring())
                {
                    myController.StartCharging();
                    attackTimer = Random.Range(0.5f, 1.5f);
                }
                // If not firing and are charging, fire
                else if (!myController.IsFiring() && myController.IsCharging())
                {
                    myController.SetLook(targetPlayer.transform.position - this.transform.position);
                    myController.FireProjectile();
                }
            }
            else
            {
                myController.SetLook(targetPlayer.transform.position - this.transform.position);
            }
        }
        else
        {
            myController.SetLook(rigidBody.velocity);
        }

        steeringForce += Containment();

        steeringForce = Vector3.ClampMagnitude(steeringForce, maxSteeringForce);

        currentForce = Vector3.ClampMagnitude(currentForce + steeringForce, maxVelocity);
        myController.Move(currentForce);
    }
示例#2
0
    private void Update()
    {
        if (myController.IsDisabled())
        {
            return;
        }

        if (Input.GetButton(chargeButtons[playerID]))
        {
            myController.StartCharging();
        }

        if (Input.GetButtonUp(chargeButtons[playerID]))
        {
            myController.FireProjectile();
        }
    }