簡體   English   中英

圖像和方向C#的導彈旋轉

[英]Missile Rotation of Image and Direction C#

我一直在擺弄MathHelp.Lerp(); 試圖找到最簡單的方法來旋轉導彈的行進方向。 現在,它會立即轉到播放器/鼠標所在的方向。

Larp是最好用的還是我應該追求的其他類型的方向旋轉? 最新帖子我的意思的例子

    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        delta = (float)gameTime.ElapsedGameTime.TotalSeconds * Speed;

        direction = mousePosition - missilePosition;
        direction.Normalize();

        missilePosition += direction * delta;

        //missilePosition = Vector2.Lerp(missilePosition, mousePosition, 2.0f);

        mouse = Mouse.GetState();

        mousePosition = new Vector2(mouse.X, mouse.Y);

        base.Update(gameTime);
    }

我一直在尋找並嘗試找出使圖像沿導彈方向旋轉的方法。 隨着方向旋轉,圖像將如何旋轉?

如果使用速度移動導彈,則可以使用此代碼(也許需要對其進行歸一化)。 從頭開始寫作。

rotation = -(float)Math.Atan2(velocity.Y, velocity.X);

因此,如果您的速度為(1,0),則表示您的錯位是從左向右直線移動。 Atan2(1,0)將為您提供1.57輻射(90度)。 要使其正常工作,您的導彈質地必須朝上。 該代碼會將其向右旋轉90度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM