SHARE
TWEET

Top Down Movement Code

rooksword Aug 13th, 2019 (edited) 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///Movement
  2.  
  3. keyboard_set_map(ord("W"), vk_up);
  4. keyboard_set_map(ord("A"), vk_left);
  5. keyboard_set_map(ord("S"), vk_down);
  6. keyboard_set_map(ord("D"), vk_right);
  7.  
  8. key_right = keyboard_check(vk_right);
  9. key_left = -keyboard_check(vk_left);
  10. key_up = -keyboard_check(vk_up);
  11. key_down = keyboard_check(vk_down);
  12.  
  13. moveh = key_right+key_left;
  14. movev = key_up+key_down;
  15.  
  16. hsp = lerp(hsp,moveh*spd,acc);
  17. vsp = lerp(vsp,movev*spd,acc);
  18.  
  19. //Horizontal collision
  20. if place_meeting(x + hsp, y, obj_wall)
  21. {
  22.     while !place_meeting(x + sign(hsp), y, obj_wall)
  23.     {
  24.         x += sign(hsp);
  25.     }
  26.     hsp = 0;
  27. }
  28. x += hsp;
  29.  
  30. //Horizontal collision
  31. if place_meeting(x, y + vsp, obj_wall)
  32. {
  33.     while !place_meeting(x, y + sign(vsp), obj_wall)
  34.     {
  35.         y += sign(vsp);
  36.     }
  37.     vsp = 0;
  38. }
  39. y += vsp;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top