Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @desc Check for the point of impact of a collision with an object in the previous frame
- /// @arg object Object to check for a collision with
- /// @arg precise Angle at which to check for collisions
- // Argument assignment
- var _obj = argument0;
- var _precise = argument1;
- var _angle = point_direction(xprevious, yprevious, x, y);
- var _distance = ceil(point_distance (xprevious, yprevious, x, y) + 1);
- // Used to check incremental positions for collisions
- var _x = 0;
- var _y = 0;
- // Loop our previous distance
- var i = 0;
- repeat ( _distance ) {
- // Calculate position of iteration
- _x = xprevious + lengthdir_x(i, _angle);
- _y = yprevious + lengthdir_y(i, _angle);
- // Check for a collision at this point
- var _collision = collision_point(_x, _y, _obj, _precise, true);
- // If a collision is found
- if (_collision != noone){
- var _impact_x = xprevious + lengthdir_x(i-1, _angle);
- var _impact_y = yprevious + lengthdir_y(i-1, _angle);
- // Return the impact coordinates
- return [ _impact_x, _impact_y, _collision ];
- }
- i += 1;
- }
- return [ -1, -1, noone ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement