Esempio n. 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);
    }
Esempio n. 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();
        }
    }
Esempio n. 3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (this.moved)
        {
            // Move this enemy.
            Vector2 newPosition = V2.FromV3(this.transform.position) + this.currentMovement;
            this.rb.MovePosition(newPosition);

            // Reset variables for next frame.
            this.currentMovement = Vector2.zero;
            this.moved           = false;
        }
    }