Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Problem with Screen Position and Rotation (XNA)

Started by programmermattc Oct 13, 2010 at 1:56 PM 0 replies 1.5k views
Original Post
programmermattc
programmermattc
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:

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?
=============================RhinoXNA - Easily start building 2D games in XNA!Projects
Zakwayda
Zakwayda
I only skimmed your code so my reply may not be particularly relevant, but make sure you're combining your translation and rotation transforms in the right order, and also make sure that you're treating the movement vector as a vector rather than a point when you transform it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.