Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***** cloned from badwrong https://pastebin.com/6YM6ykBC ********/
- /// @function collision_line_point(_x1, _y1, _x2, _y2, _object, _precision, _notme)
- /// @param {real} _x1 The x coordinate of the start of the line
- /// @param {real} _y1 The y coordinate of the start of the line
- /// @param {real} _x2 The x coordinate of the end of the line
- /// @param {real} _y2 The y coordinate of the end of the line
- /// @param {index} _object The object to check for instance collisions
- /// @param {bool} _precision Whether or not to use precise collision checking (slower)
- /// @param {bool} _notme Whether or not to check for collision with the calling instance
- /// @description A collision line function which returns an array with the instance and impact point of collision
- function collision_line_point(_x1, _y1, _x2, _y2, _object, _precision, _notme)
- {
- var _inst = collision_line(_x1, _y1, _x2, _y2, _object, _precision, _notme),
- _rx = _x1,
- _ry = _y1;
- if (_inst != noone) {
- var _count = ceil(log2(point_distance(_x1, _y1, _x2, _y2))) + 1,
- _p0 = 0,
- _p1 = 1;
- _x2 -= _x1;
- _y2 -= _y1;
- repeat (_count) {
- var _np = _p0 + (_p1 - _p0) * 0.5,
- _nx = _x1 + _x2 * _np,
- _ny = _y1 + _y2 * _np,
- _px = _x1 + _x2 * _p0,
- _py = _y1 + _y2 * _p0,
- _inst2 = collision_line(_px, _py, _nx, _ny, _object, _precision, _notme);
- if (_inst2 != noone) {
- _inst = _inst2;
- _rx = _nx;
- _ry = _ny;
- _p1 = _np;
- } else _p0 = _np;
- }
- }
- // Returns instance id (or noone), and the impact x/y
- return [_inst, _rx, _ry];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement