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 7515265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:45:04+00:00 2026-05-30T00:45:04+00:00

I want to move a 3d car model, when I press the left or

  • 0

I want to move a 3d car model, when I press the left or right arrow key I change the angle, when I press the up arrow the car drives.

This is the code in the update method:

float dirX = (float)Math.Sin(angle);
float dirY = (float)Math.Cos(angle);

if (Keyboard.GetState().IsKeyDown(Keys.Up))
        {
            position += new Vector3(-dirX, dirY, 0);

            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                angle += 0.015f;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                angle -= 0.015f;
            }
        }

This is the calculating part, but obviously I also need to move the car on the screen.
I want the car to move forward, not up, so I thought I should rotate it 90 degrees on the X axis, and also I want to rotate the car when I press the left or right keys.

I wrote this code:

world = Matrix.CreateTranslation(position) * Matrix.CreateRotationY(angle) * Matrix.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(-90));

This code isn’t working, can anybody tell me how can I move it?

  • 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-05-30T00:45:06+00:00Added an answer on May 30, 2026 at 12:45 am

    You should be aware that your Y axis is actually “up”, not “forward” (by conventions). While this problem has many solutions, quickest way to fix yours is that:

    float dirX = (float)Math.Sin(angle);
    float dirZ = (float)Math.Cos(angle);
    
    position += new Vector3(dirX, 0, dirZ); 
    

    Then, you should multiply your transformation matrices in the correct order:

    Scale * Rotation * Translation
    

    Which in your case translates to:

    // this will rotate car around the Y axis, and then translate it to correct location
    world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(position);
    

    One suggestion, do as A-Type suggested, and use direction * speed.

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

Sidebar

Related Questions

I want to move the board I create using left arrow to move left
I am new to javascript.I want to move a car on path with arrows.I
I want to move my form window by left-clicking and holding on the background
I want to move a image across the screen by 16 to the right
I want to move nodes in nokogiri to a parent. I have this: <root>
I have a draggable which on the stop event, I want move to a
I want to move various parts of my app into simple scripts, to allow
I want to move about 800gb of data from an NTFS storage device to
I want to move the form title, icon and close, and help buttons from
I want to move a file with Ruby. How do I do that?

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.