Original Post
I am having an issue in an asteroids-style game where theplayer will pass the screen borders and the code makes them appear on the opposite screen edge (for example, passing too far to the right makes you appear on the left).
However, it seems like the movement vector I use to define which was to go gets all messed up until I rotate and fly around for awhile. Here is some of my ship rotation code where I believe the issue is happening:
The 240 offset in the rotation is compensation for the movement vector (which, while typing this I realized a solution for).
Does anyone see why, if the this.Position changes to the other side of the screen, the transformation of this vector wouldn't work properly?
However, it seems like the movement vector I use to define which was to go gets all messed up until I rotate and fly around for awhile. Here is some of my ship rotation code where I believe the issue is happening:
private void UpdateRotationData(KeyboardState kbs) { if (kbs.IsKeyDown(Keys.A)) { this.Rotation -= MathHelper.ToRadians(5); float translatedRot = MathHelper.ToRadians(MathHelper.ToDegrees (this.Rotation) + 240); Matrix transform = new Matrix(); transform = Matrix.CreateTranslation(new Vector3(this.Position, 1.0f)) * Matrix.CreateRotationZ(translatedRot); _movementDir = Vector2.Transform(_movementDir, transform); _movementDir.Normalize(); } if (kbs.IsKeyDown(Keys.D)) { this.Rotation += MathHelper.ToRadians(5); float translatedRot = MathHelper.ToRadians(MathHelper.ToDegrees (this.Rotation) + 240); Matrix transform = new Matrix(); transform = Matrix.CreateTranslation(new Vector3(this.Position, 1.0f)) * Matrix.CreateRotationZ(translatedRot); _movementDir = Vector2.Transform(_movementDir, transform); _movementDir.Normalize(); } } The 240 offset in the rotation is compensation for the movement vector (which, while typing this I realized a solution for).
Does anyone see why, if the this.Position changes to the other side of the screen, the transformation of this vector wouldn't work properly?