太空射击,射击bug

时间:2013-10-08 14:57:43

标签: c# xna

我有一个带有旋转运动和射击的太空射击游戏,但是当我拍摄时子弹向左或向右略微向左移动时如何解决这个问题谢谢:)

Bullets newBullet = new Bullets(Content.Load<Texture2D>("PlayerBullet"));
newBullet.velocity = new Vector2((float)Math.Cos(rotation),
                                 (float)Math.Sin(rotation)) * 5f + playerVelocity;
newBullet.position = playerPosition + newBullet.velocity * 5;

这里有一些我认为导致问题的代码

3 个答案:

答案 0 :(得分:2)

我相信你的位置和速度计算不正确。

初始位置应该只是玩家的位置(如果携带枪,可能还有一个偏移)

newBullet.position = playerPosition;

我不确定你为什么要把球员速度添加到子弹中。为什么玩家移动的速度有多重要?如果只是一个速度系数,我也假设* 5f

newBullet.velocity = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * 5f;

尝试一下,看看是否解决了这个问题。

答案 1 :(得分:0)

我希望子弹的初始位置是

newBullet.position = playerPosition + playerVelocity * 5;

而不是

newBullet.position = playerPosition + newBullet.velocity * 5;

答案 2 :(得分:0)

我打赌你在创建子弹后更新你的玩家位置,主要是生成子弹,然后向左或向右移动玩家对象。

确保在使用它来定位子弹,相机等之前完成了玩家位置的更改。