Example #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float   magnitude = this.speed * Time.deltaTime;
        Vector2 movement  = V2.FromMagnitudeAngle(magnitude, this.angle);

        this.rb.MovePosition(V2.FromV3(this.transform.position) + movement);
    }
Example #2
0
    void FixedUpdate()
    {
        // Do movement.
        if (this.input.IsMoving())
        {
            float   magnitude   = this.speed * Time.deltaTime;
            float   angle       = this.input.GetMovementDirection();
            Vector2 movement    = V2.FromMagnitudeAngle(magnitude, angle);
            Vector2 newPosition = V2.FromV3(this.transform.position) + movement;

            // Prevent player from moving beyond the edges of the screen.
            float halfWidth  = this.width * 0.5f;
            float halfHeight = this.height * 0.5f;
            newPosition.x = Mathf.Clamp(newPosition.x, halfWidth, Stage.instance.width - halfWidth);
            newPosition.y = Mathf.Clamp(newPosition.y, halfHeight, Stage.instance.height - halfHeight);

            this.rb.MovePosition(newPosition);
            this.bodyAnimator.SetFloat(BLEND_PARAM_HORIZONTAL_VELOCITY, movement.x);
        }
        else
        {
            this.bodyAnimator.SetFloat(BLEND_PARAM_HORIZONTAL_VELOCITY, 0f);
        }

        // Do firing.
        if (this.input.IsFiring())
        {
            this.gun.Fire();
        }
    }
    private void PickNewTarget()
    {
        float   magnitude  = Random.value * this.maxRadiusFromCenter;
        float   angle      = Random.value * Mathf.PI * 2f;
        Vector2 nextTarget = V2.FromMagnitudeAngle(magnitude, angle);

        this.vectorFromStartToTarget = nextTarget - this.currentTarget;
        this.currentTarget           = nextTarget;
        this.progressToTarget        = 0;
        this.stopMovingTime          = Time.time + this.driftInterval - this.stayAtTargetDuration;
        this.nextDriftTime           = Time.time + this.driftInterval;
    }