Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. You can think of it like this:
  2. You have two variables, var_speed and direction.
  3. You can represent that movement with trigonometric functions like this:
  4. hspeed=+var_speed*cos(direction), and
  5. vspeed=-var_speed*sin(direction) //Minus here because in Game Maker the Y axis is inverted.
  6. Since sin(a)^2+cos(a)^2=1, the total speed will always be equal to var_speed.
  7.  
  8. With that said, if you just want simple 45-degree diagonal movement, you just need to set
  9. vspeed=+/-var_speed/sqrt(2), and
  10. hspeed=+/-var_speed/sqrt(2).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement