Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Approach script by Matt Thorson (http://mattmakesgames.com/)
  2. //example:
  3. //horizontal_speed = approach(horizontal_speed, MAX_HORIZONTAL_SPEED, acceleration);
  4.  
  5. /*
  6. APPROACH
  7. 0 - start point
  8. 1 - end point
  9. 2 - max change
  10.  
  11. Returns 0 shifted toward 1 by 2, without crossing 0.
  12. Note that if argument2 is negative, you will move AWAY from 0.
  13. Ex:
  14. approach( 5, 0, 2 )     = 3
  15. approach( -5, 0, 2 )    = -3
  16. approach( 1, 0, 1 )     = 0
  17. approach( 1, 0, 2 )     = 0
  18. */
  19.  
  20. if ( argument0 < argument1 )
  21.     return min( argument0+argument2, argument1 );
  22. else
  23.     return max( argument0-argument2, argument1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement