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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:12:20+00:00 2026-06-17T21:12:20+00:00

I am building a driving game. The view is a perspective one and the

  • 0

I am building a driving game. The view is a perspective one and the player’s perspective is from behind the car which is driving forward. When the car is driving forward, all the environment around it moves downwards and scales (This is looking quite good now) which gives the impression of the car moving forward. Now, I want to have some realistic driving controls, so that the car builds up speed and then slows down gradually when the up arrow is released. Currently, I call all the move functions for several sprites when the up arrow is pressed. I am looking for a way to control this so that the functions are not called as often when the car is slow etc etc. The code I have so far is:

   protected void Drive()
    {
        KeyboardState keyState = Keyboard.GetState();

        if (keyState.IsKeyDown(Keys.Up))
        {
            MathHelper.Clamp(++TruckSpeed, 0, 100);
        }
        else
        {
            MathHelper.Clamp(--TruckSpeed, 0, 100);
        }

        // Instead of using the condition below, I want to use the TruckSpeed
        // variable some way to control the rate at which these are called 
        // so I can give the impression of acceleration and de-acceleration.

        if (keyState.IsKeyDown(Keys.Up))
        {
            // Lots of update calls in here
        }
   }

I thought this should be easy but for some reason, I cannot make any sense out of it. Would really appreciate some help here! Thanks

  • 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-17T21:12:22+00:00Added an answer on June 17, 2026 at 9:12 pm

    First suggestion, don’t use ++ and --. Make your TruckSpeed increase at a rate multiplied by the Delta Time. This means that your acceleration and deceleration will work the same on slower and faster computers and will be independent of frame rate hickups. You can also have different increase and decrease rates for better control over your gameplay.

    Something along the lines of:

    protected void Drive(GameTime gameTime) // Pass your game time
    {
        KeyboardState keyState = Keyboard.GetState();
        if (keyState.IsKeyDown(Keys.Up))
        {
            TruckSpeed += AccelerationRatePerSecond * gameTime.ElapsedGameTime.TotalSeconds;
        }
        else
        {
            TruckSpeed -= DecelerationRatePerSecond * gameTime.ElapsedGameTime.TotalSeconds;
        }
        MathHelper.Clamp(TruckSpeed, 0, 100);
        ...
    

    Also, you can probably replace

    if (keyState.IsKeyDown(Keys.Up))
    

    by

    if (TruckSpeed > 0)
    

    It’s probably simpler to attach the camera to your model and move that in the environment instead of moving your entire environment around the Truck though…

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

Sidebar

Related Questions

I am working on building a little game program like this one for a
This is driving me crazy. I am building a page which will only have
I am building a library of asp.net user controls which I am deriving from
Building a search with some custom objects and three scopes: All , Active ,
I'm diving into iOS development and am building a game that has multiple game
Minor issue, but it's driving me nuts nonetheless. I'm building a url for a
I'm diving into Ruby on Rails and building a web game where the user
I've search all over the web and this problem is driving me crazy. I'm
I am building a system which asks questions and receives answers to them. Each
Building a test web service and all was working great, so I added 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.