导弹旋转图像和方向C#

时间:2014-03-28 13:05:16

标签: c# xna rotation image-rotation directions

我一直在摆弄MathHelp.Lerp();试图找到最简单的方法来旋转导弹的行进方向。现在它会立即朝着播放器/鼠标的方向发展。

Larp是最好用的还是其他类型的方向旋转是我应该追求的? Latest postexample of what I mean

    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);
    }

让图像随着导弹的方向旋转也是我一直在寻找并试图找出的东西。当方向旋转时,我如何旋转图像?

1 个答案:

答案 0 :(得分:0)

如果使用速度移动导弹,则可以使用此代码(可能需要对其进行标准化)。从头上写。

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

所以如果你的速度是(1,0)意味着你的misslile从左到右直线。 Atan2(1,0)会给你1.57个辐射(90度)。为了使这个工作,你的导弹质地必须面朝上。这段代码会把它转到90度,在右边。

相关问题