Skip to main content
Cleanup
Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

2d diagonally How to fix diagonal velocity being greater than straightaxis-line velocity. How to fixaligned?

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?

enter image description hereWith adjustment enter image description hereNo adjustment

2d diagonally velocity greater than straight-line velocity. How to fix?

If I have a topdown rpg type game. And movement in 8 directions (N/E/S/W/NE/NW/SE/SW) in a 2d game that involves both x and y velocity. I'm finding when i'm moving in the diagonal directions i'm building both x and y velocity and its making my character move faster than they do in straightline directions. Is there a fix for this so no matter what of the 8 I travel its the same speed?

so say...
vel_x, vel_y=0
spd=1

then in my gameloop
vel_x*=0.2
vel_y*=0.2

Then my button presses add/subtract the spd value from their corresponding velocity direction x/y when pressed.
then I add the vel_x to my x sprite position and same with vel_y for my y sprite

How would I address this...? Would I look at btn press actions for when both keys are
held....or limits for when vel_x AnD vel_y are 'high' enough in tandem.... 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 Left moving at same speed all the time and right isn't?

enter image description here enter image description here

How to fix diagonal velocity being greater than axis-aligned?

I have a 2D top-down RPG type game, with movement in 8 directions (N/E/S/W/NE/NW/SE/SW) involving both x and y velocity. 

I'm finding when I'm moving in the diagonal directions, I'm building both x and y velocity and it's making my character move faster than they do in a straight line along only x or only y. Is there a fix for this, so no matter which of the 8 directions I travel along, it's the same speed?

My code works like this. I initialize my variables and speed:

vel_x, vel_y=0  
spd=1

Then each frame in my game loop, I apply drag to reduce the velocity:

vel_x*=0.2  
vel_y*=0.2

Then my button presses add/subtract the spd value from their corresponding velocity direction x/y when pressed.

Lastly, I add the vel_x to my sprite's x position and same with vel_y for my sprite's y position.

How would I address this? Would I look at button press actions for when both keys are held, or limits for when vel_x and vel_y are 'high' enough in tandem?

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 left moving at same speed all the time and right isn't?

With adjustment No adjustment

added 85 characters in body
Source Link
kite
  • 207
  • 1
  • 9

If I have a topdown rpg type game. And movement in 8 directions (N/E/S/W/NE/NW/SE/SW) in a 2d game that involves both x and y velocity. I'm finding when i'm moving in the diagonal directions i'm building both x and y velocity and its making my character move faster than they do in straightline directions. Is there a fix for this so no matter what of the 8 I travel its the same speed?

so say...
vel_x, vel_y=0
spd=1

then in my gameloop
vel_x*=0.2
vel_y*=0.2

Then my button presses add/subtract the spd value from their corresponding velocity direction x/y when pressed.
then I add the vel_x to my x sprite position and same with vel_y for my y sprite

How would I address this...? Would I look at btn press actions for when both keys are
held....or limits for when vel_x AnD vel_y are 'high' enough in tandem.... 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 Left moving at same speed all the time and right isn't?

enter image description here enter image description here

If I have a topdown rpg type game. And movement in 8 directions (N/E/S/W/NE/NW/SE/SW) in a 2d game that involves both x and y velocity. I'm finding when i'm moving in the diagonal directions i'm building both x and y velocity and its making my character move faster than they do in straightline directions. Is there a fix for this so no matter what of the 8 I travel its the same speed?

so say...
vel_x, vel_y=0
spd=1

then in my gameloop
vel_x*=0.2
vel_y*=0.2

Then my button presses add/subtract the spd value from their corresponding velocity direction x/y when pressed.
then I add the vel_x to my x sprite position and same with vel_y for my y sprite

How would I address this...? Would I look at btn press actions for when both keys are
held....or limits for when vel_x AnD vel_y are 'high' enough in tandem.... I've done the latter and it helps but I can't make it accurate.

enter image description here

If I have a topdown rpg type game. And movement in 8 directions (N/E/S/W/NE/NW/SE/SW) in a 2d game that involves both x and y velocity. I'm finding when i'm moving in the diagonal directions i'm building both x and y velocity and its making my character move faster than they do in straightline directions. Is there a fix for this so no matter what of the 8 I travel its the same speed?

so say...
vel_x, vel_y=0
spd=1

then in my gameloop
vel_x*=0.2
vel_y*=0.2

Then my button presses add/subtract the spd value from their corresponding velocity direction x/y when pressed.
then I add the vel_x to my x sprite position and same with vel_y for my y sprite

How would I address this...? Would I look at btn press actions for when both keys are
held....or limits for when vel_x AnD vel_y are 'high' enough in tandem.... 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 Left moving at same speed all the time and right isn't?

enter image description here enter image description here

added 95 characters in body
Source Link
kite
  • 207
  • 1
  • 9

If I have a topdown rpg type game. And movement in 8 directions (N/E/S/W/NE/NW/SE/SW) in a 2d game that involves both x and y velocity. I'm finding when i'm moving in the diagonal directions i'm building both x and y velocity and its making my character move faster than they do in straightline directions. Is there a fix for this so no matter what of the 8 I travel its the same speed?

so say...
vel_x, vel_y=0
spd=1

then in my gameloop
vel_x*=0.2
vel_y*=0.2

Then my button presses add/subtract the spd value from their corresponding velocity direction x/y when pressed.
then I add the vel_x to my x sprite position and same with vel_y for my y sprite

How would I address this...? Would I look at btn press actions for when both keys are
held....or limits for when vel_x AnD vel_y are 'high' enough in tandem.... I've done the latter and it helps but I can't make it accurate.

enter image description here

If I have a topdown rpg type game. And movement in 8 directions (N/E/S/W/NE/NW/SE/SW) in a 2d game that involves both x and y velocity. I'm finding when i'm moving in the diagonal directions i'm building both x and y velocity and its making my character move faster than they do in straightline directions. Is there a fix for this so no matter what of the 8 I travel its the same speed?

so say...
vel_x, vel_y=0
spd=1

then in my gameloop
vel_x*=0.2
vel_y*=0.2

Then my button presses add/subtract the spd value from their corresponding velocity direction x/y when pressed.
then I add the vel_x to my x sprite position and same with vel_y for my y sprite

How would I address this...? Would I look at btn press actions for when both keys are
held....or limits for when vel_x AnD vel_y are 'high' enough in tandem.... I've done the latter and it helps but I can't make it accurate.

If I have a topdown rpg type game. And movement in 8 directions (N/E/S/W/NE/NW/SE/SW) in a 2d game that involves both x and y velocity. I'm finding when i'm moving in the diagonal directions i'm building both x and y velocity and its making my character move faster than they do in straightline directions. Is there a fix for this so no matter what of the 8 I travel its the same speed?

so say...
vel_x, vel_y=0
spd=1

then in my gameloop
vel_x*=0.2
vel_y*=0.2

Then my button presses add/subtract the spd value from their corresponding velocity direction x/y when pressed.
then I add the vel_x to my x sprite position and same with vel_y for my y sprite

How would I address this...? Would I look at btn press actions for when both keys are
held....or limits for when vel_x AnD vel_y are 'high' enough in tandem.... I've done the latter and it helps but I can't make it accurate.

enter image description here

Source Link
kite
  • 207
  • 1
  • 9
Loading