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

  • Home
  • SEARCH
  • 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 6003299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:06:07+00:00 2026-05-23T01:06:07+00:00

I am trying to add the ability for the camera to go up and

  • 0

I am trying to add the ability for the camera to go up and down on the Y axis, something it currently does not support. I have tried adding to the Y value when W and or S is pressed but it doesn’t work correctly. What kind of formula do I need? I know it has to do with the pitch and adding to the Y axis.

void WALKING_CAMERA::Update(double time)
{
    //calculate the distance to move, based on time passed
    static double lastTime=time;
    double timePassed=time-lastTime;
    lastTime=time;

    float distance=speed*(float)timePassed/1000;

    //Get the mouse position
    POINT mPos;
    GetCursorPos(&mPos);

    angleYaw+=((float)mPos.x-320.0f)*speed/20;
    anglePitch+=((float)mPos.y-240.0f)*speed/20;

    //make sure angleY is not too great
    if(anglePitch>85.0f)
        anglePitch=85.0f;

    if(anglePitch<-85.0f)
        anglePitch=-85.0f;

    //set the mouse back to the centre of the screen
    SetCursorPos(320,240);

    //move forward/back or strafe
    if(window.isKeyPressed(VK_UP) || window.isKeyPressed('W'))
    {
        position.x += (float)sin(angleYaw*M_PI/180)*distance*25;
        position.z -= (float)cos(angleYaw*M_PI/180)*distance*25;
    }

    if(window.isKeyPressed(VK_DOWN) || window.isKeyPressed('S'))
    {
        position.x -= (float)sin(angleYaw*M_PI/180)*distance*25;
        position.z += (float)cos(angleYaw*M_PI/180)*distance*25;
    }

    if(window.isKeyPressed(VK_RIGHT) || window.isKeyPressed('D'))
    {
        position.x += (float)cos(angleYaw*M_PI/180)*distance*25;
        position.z += (float)sin(angleYaw*M_PI/180)*distance*25;
    }

    if(window.isKeyPressed(VK_LEFT) || window.isKeyPressed('A'))
    {
        position.x -= (float)cos(angleYaw*M_PI/180)*distance*25;
        position.z -= (float)sin(angleYaw*M_PI/180)*distance*25;
    }
}

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-05-23T01:06:07+00:00Added an answer on May 23, 2026 at 1:06 am

    For forward movement, something to this effect should work:

    position.y += (float)sin(anglePitch * M_PI / 180) * distance * 25;
    

    You may have to reverse the sign, as I’m not sure whether your application uses positive or negative Y values for upward movement.

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

Sidebar

Related Questions

I have a WinForms app and am trying to add the ability to start
So I'm trying to add some ability to my project to allow user-defined properties
Trying to add a dynamic class value to one of my columns in CGridView:
one thing i can not get straight is the ability to add html without
Using MS Visual C++ and Boost asio, I'm trying to add the ability to
In Android, I'm trying to accomplish this: Basically, the ability to add the button
Trying to add the ability to delete a Folder using FTP and all subfolders
I am trying to add in the ability for users of my app to
Trying to add a 'box' to a form at design time, I looked up
Trying to add email notification to my app in the cleanest way possible. When

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.