Jump to content


Photo

8 Way Movement


  • Please log in to reply
5 replies to this topic

#1 remmies

remmies

    GMC Member

  • GMC Member
  • 119 posts
  • Version:GM:Studio

Posted 05 February 2011 - 09:15 PM

So my movement code is:

//Variables
KEY_LEFT = keyboard_check_direct(ord('A'))
KEY_RIGHT = keyboard_check_direct(ord('D'))
KEY_DOWN = keyboard_check_direct(ord('S'))
KEY_UP = keyboard_check_direct(ord('W'))
KEY_LEFTR = keyboard_check_released(ord('A'))
KEY_RIGHTR = keyboard_check_released(ord('D'))
KEY_DOWNR = keyboard_check_released(ord('S'))
KEY_UPR = keyboard_check_released(ord('W'))

//WSAD Movement

if KEY_UP
{
action_potential_step(x,y-walksp,walksp,0)
}

if KEY_DOWN
{
action_potential_step(x,y+walksp,walksp,0)
}

if KEY_LEFT
{
action_potential_step(x-walksp,y,walksp,0)
}

if KEY_RIGHT
{
action_potential_step(x+walksp,y,walksp,0)
}


if KEY_UPR
or KEY_DOWNR
or KEY_LEFTR
or KEY_DOWNR
{
speed = 0
}

So my problem is when I move with up and left then I seem to go twice as fast, how can I slow it down to match the speed of just hitting one direction?
  • 0

#2 Davve

Davve

    GMC Member

  • GMC Member
  • 3927 posts
  • Version:GM:Studio

Posted 05 February 2011 - 09:17 PM

x += (keyboard_check(ord("D")) - keyboard_check(ord("A"))) * 4;
y += (keyboard_check(ord("S")) - keyboard_check(ord("W"))) * 4;

Edit: Changed to WASD
Edit2: Take a look at the signature rules.

Edited by Davve, 05 February 2011 - 09:19 PM.

  • 0

#3 Canite

Canite

    Canigget

  • GMC Member
  • 1358 posts
  • Version:GM8

Posted 05 February 2011 - 09:21 PM

Well, think about it like a triangle. When moving straight up,down,left, or right, you're moving along one side of the triangle. When moving diagonally, you're moving about the hypotenuse of the triangle. The hypotenuse is always longer than the sides, so therefore you are moving more distance in the same amount of time (not twice as fast). So, you need to find a formula that will give you a hypotenuse length the same as the length of one of the individual sides. You'll probably be using a^2 + b^2 = c^2.
  • 0

#4 sargunster

sargunster

    GMC Member

  • New Member
  • 449 posts

Posted 05 February 2011 - 09:22 PM

You could use lengthdir_x and lengthdir_y, or just use 2.8 instead of 4 when moving diagonally.

http://www.google.co...l=en&q=sqrt(2*4)&aq=f&aqi=&aql=&oq=&pbx=1&fp=6aaff458859385c2
  • 0

#5 TidalEspeon257

TidalEspeon257

    GMC Member

  • New Member
  • 83 posts

Posted 05 February 2011 - 09:54 PM

You could add some "and not" statements to specify what direction to move. Something like an
key_up and key_right and not key_left and not key_down
would get the character only move northeast, similar code for one direction would work too. basically its telling gm
"if the up and the right keys are the only movement keys pressed, then move it as so."

I know you're using WSAD and not the arrows, but its the same concept.

I hope that helps :) though i might be wrong, since searching action_potential_step in the help file got me nothing ^^;
  • 0

#6 sargunster

sargunster

    GMC Member

  • New Member
  • 449 posts

Posted 05 February 2011 - 09:58 PM

He means that going east 4 and north 4 makes it go 5.7 northeast.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users