Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8544103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:28:22+00:00 2026-06-11T12:28:22+00:00

Good day. I’m working on a fps game, and I have a problem with

  • 0

Good day. I’m working on a fps game, and I have a problem with camera, or with movement to be pricese… as it doesn’t take camera position into accound when performs movement…
I tried to fix it in several different ways, but I guess I just don’t understand the math needed 🙁

Anyway, here’s the code:

    static public void UpdateCharacterPositionAndCamera(float time)
    {
        //mouse look update
        float rotationSpeed = 3f;
        if (Input.mouseState != Input.mouseStatePrevious)
        {
            float xDifference = Input.mouseState.X - Display.gd.Viewport.Width / 2;
            float yDifference = Input.mouseState.Y - Display.gd.Viewport.Height / 2;
            yRotation -= rotationSpeed * xDifference * time;
            xRotation -= rotationSpeed * yDifference * time;
            Mouse.SetPosition(Display.gd.Viewport.Width / 2, Display.gd.Viewport.Height / 2);
        }

        //camera
        Vector3 cameraPosition = playerPos;
        Vector3 cameraReference = new Vector3(0f, 0f, -1f);
        Matrix rotationMatrix = Matrix.CreateRotationY(MathHelper.ToRadians(yRotation)) * Matrix.CreateRotationX(MathHelper.ToRadians(xRotation));
        Vector3 transformedReference = Vector3.Transform(cameraReference, rotationMatrix);
        Vector3 cameraLookat = cameraPosition + transformedReference;
        viewMatrix = Matrix.CreateLookAt(cameraPosition, cameraLookat, new Vector3(0.0f, 1.0f, 0.0f));
        projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Display.gd.Viewport.AspectRatio, 0.1f, 2500.0f);

        //movement
        float moveSpeed = 5.0f;
        Vector3 moveVector = new Vector3(0, 0, 0);
        if (Input.keyState.IsKeyDown(Keys.Up) || Input.keyState.IsKeyDown(Keys.W))
            moveVector += new Vector3(0, 0, -1);
        if (Input.keyState.IsKeyDown(Keys.Down) || Input.keyState.IsKeyDown(Keys.S))
            moveVector += new Vector3(0, 0, 1);
        if (Input.keyState.IsKeyDown(Keys.Right) || Input.keyState.IsKeyDown(Keys.D))
            moveVector += new Vector3(1, 0, 0);
        if (Input.keyState.IsKeyDown(Keys.Left) || Input.keyState.IsKeyDown(Keys.A))
            moveVector += new Vector3(-1, 0, 0);
        if (Input.keyState.IsKeyDown(Keys.Q))
            moveVector += new Vector3(0, 1, 0);
        if (Input.keyState.IsKeyDown(Keys.Z))
            moveVector += new Vector3(0, -1, 0);
        playerPos += moveVector * moveSpeed;
    }

Can you tell me how to change the move vector so it takes camera direction into account…?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:28:24+00:00Added an answer on June 11, 2026 at 12:28 pm

    Multiply the move vector by the camera rotation matrix, or its inverse (I think it’s the inverse). It’s the same as the view matrix, but without the translation. If you want to fix the camera onto a plane, you need to zero out the respective component afterwards and perhaps normalize the new vector.
    I’m not familiar with the XNA API, so I cannot tell you exactly which methods to use. You might be able to extract the rotation matrix from the view matrix, or you might need to look at the difference (lookAt-positios) from the origin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Day, I have a simple working routine in Perl that swaps two words:
Good day, to stackoverflow community. I have run into a bug with regard to
Good Day!!! I have a problem with the layout specially in the landscape orientation
Good Day all, i have been working with http://jsfiddle.net , the sample app i
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, I have like 15 images I need to be buttons. I have
Good day everyone, I'm an independent game developer who has, in the past, primarily
Good day, I have a gen_server process which does some long-running state-updating tasks periodically
Good day I have a basic toolbar to which I added ImageIcon buttons. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.