[英]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.