Sunday, June 12, 2022
HomeGame Developmentc++ - Motion diagonally just isn't constant

c++ – Motion diagonally just isn’t constant


I’m making my very own sport and that is the primary time i am doing so. so I hope you possibly can forgive silly errors. Im making this in C++ and utilizing the SDL2 framework.

Presently, I’ve a personality on my display which i’m making an attempt to maneuver throughout the display.
I’m encountering an especially unusual bug the place transferring southwest is completely different to transferring north east (reverse instructions). transferring SW appears to work accurately however going NE is incorrect. When the character strikes NE, it doesn’t go east sufficient. so if SW motion is 225 levels from north clockwise (appropriate), then NE is simply transferring 25 levels from north clockwise (incorrect). NE motion ought to be 45 levels however it’s 25 levels. What potential cause may there be for this taking place?

I additionally observed that transferring north west is quicker than transferring south east.
I attempted to troubleshoot by timing every route to see if its any specific route not working. however to my shock, if I solely press 1 motion key, all instructions have constant timings.
I’m at a whole loss and that i don’t know what’s going on.

void updateVel(const Uint8 *state) {
    velY = maxVel * (state[SDL_SCANCODE_S] - state[SDL_SCANCODE_W]);
    velX = maxVel * (state[SDL_SCANCODE_D] - state[SDL_SCANCODE_A]);

    //if going diagonal, decelerate to restrict diagonal pace.
    if (velX != 0 && velY != 0) {
        velX *= 0.707f;
        velY *= 0.707f;
    }
    std::cout << velX << " " << velY << std::endl;
// velX, velY, and maxVel are all floats. 
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments