SHARE
TWEET

Untitled

a guest Sep 15th, 2019 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @desc Check for the point of impact of a collision with an object in the previous frame
  2. /// @arg object Object to check for a collision with
  3. /// @arg precise Angle at which to check for collisions
  4.  
  5. // Argument assignment
  6. var _obj        = argument0;
  7. var _precise    = argument1;
  8. var _angle      = point_direction(xprevious, yprevious, x, y);
  9. var _distance   = ceil(point_distance (xprevious, yprevious, x, y) + 1);
  10.  
  11. // Used to check incremental positions for collisions
  12. var _x = 0;
  13. var _y = 0;
  14.  
  15. // Loop our previous distance
  16. var i = 0;
  17. repeat ( _distance ) {
  18.    
  19.     // Calculate position of iteration
  20.     _x = xprevious + lengthdir_x(i, _angle);
  21.     _y = yprevious + lengthdir_y(i, _angle);
  22.    
  23.     // Check for a collision at this point
  24.     var _collision = collision_point(_x, _y, _obj, _precise, true);
  25.    
  26.     // If a collision is found
  27.     if (_collision != noone){
  28.         var _impact_x = xprevious + lengthdir_x(i-1, _angle);
  29.         var _impact_y = yprevious + lengthdir_y(i-1, _angle);
  30.            
  31.         // Return the impact coordinates
  32.         return [ _impact_x, _impact_y, _collision ];
  33.     }
  34.    
  35.     i += 1;
  36. }
  37.  
  38. return [ -1, -1, noone ];
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top