If I have a topdown rpg2D top-down RPG type game. And, with movement in 8 directions (N/E/S/W/NE/NW/SE/SW) in a 2d game that involvesinvolving both x and y velocity.
I'm finding when i'mI'm moving in the diagonal directions i'm, I'm building both x and y velocity and itsit's making my character move faster than they do in straightline directionsa straight line along only x or only y. Is there a fix for this, so no matter whatwhich of the 8 directions I travel itsalong, it's the same speed?
so say..My code works like this.
vel_x, vel_y=0
spd=1 I initialize my variables and speed:
vel_x, vel_y=0
spd=1
thenThen each frame in my gameloop
vel_x*=0.2
vel_y*=0.2game loop, I apply drag to reduce the velocity:
vel_x*=0.2
vel_y*=0.2
Then my button presses add/subtract the spdspd
value from their corresponding velocity direction x/y when pressed.
then
Lastly, I add the vel_xvel_x
to my sprite's x sprite position and same with vel_yvel_y
for my sprite's y spriteposition.
How would I address this...? Would I look at btnbutton press actions for when both keys are
held....or held, or limits for when vel_x AnD vel_yvel_x
and vel_y
are 'high' enough in tandem....
I've?
I've done the latter and it helps, but I can't make it accurate.
Images: With velocity removed and just +-1 speed increases/decreases. Left is the proposed adjustment to the vertical movement. Right is no adjustment. Is Leftleft moving at same speed all the time and right isn't?