【问题标题】:Missile Rotation of Image and Direction C#图像和方向的导弹旋转 C#
【发布时间】:2014-03-28 13:05:15
【问题描述】:

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

拉普是最好用的还是其他类型的方向旋转是我应该追求的? Latest post, example 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);
    }

让图像随着导弹的方向旋转也是我一直在寻找并试图弄清楚的事情。我如何让图像随着方向的旋转而旋转?

【问题讨论】:

  • 我刚刚发现了一些我可以使用的东西here 我还在阅读它,但也许可以从这里得到答案...
  • 我会做这样的事情:找出目标和导弹之间的角度,有一个预定义的maximumturnangle,如果转向角度大于maximumturnangle,旋转导弹很多度。如果角度小于maximumturnangle,则将导弹旋转到所需的量。
  • 谢谢,我会试试的。

标签: c# xna rotation image-rotation directions


【解决方案1】:

如果您使用速度来移动导弹,则可以使用此代码(也许您需要对其进行标准化)。从头开始写作。

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

因此,如果您的速度为 (1,0),则意味着您的导弹从左向右直行。 Atan2(1,0) 会给你 1.57 个辐射点(90 度)。为了使这个工作,你的导弹纹理必须面朝上。这段代码会将它向右旋转 90 度。

【讨论】:

  • 我可以这样做,我会试试这个旋转是从哪里来的?
猜你喜欢
  • 2018-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-27
  • 1970-01-01
  • 2014-01-03
  • 2021-02-19
  • 2021-11-22
相关资源
最近更新 更多