You are not logged in.
/// collision_raycast(x1, y1, x2, y2, obj, prec, notme, [max_dist])
//
// Returns id of collision hit ("noone" if no collision)
// Saves impact coordinates in "raycast_hit_x" and "raycast_hit_y" (saves "noone" if no collision)
//
/// GMLscripts.com/license
{
raycast_hit_x = noone;
raycast_hit_y = noone;
var x1, y1, x2, y2, obj, prec, notme, max_dist, tdir, tdist, ret_val;
x1 = argument[0];
y1 = argument[1];
x2 = argument[2];
y2 = argument[3];
obj = argument[4];
prec = argument[5];
notme = argument[6];
tdir = point_direction(x1, y1, x2, y2);
tdist = point_distance(x1, y1, x2, y2);
ret_val = noone;
max_dist = tdist;
if (argument_count > 7) {
max_dist = argument[7];
if (max_dist > tdist) {max_dist = tdist;}
}
var xx, yy;
xx = x1;
yy = y1;
for (var i = 0; i < max_dist; i++) {
var col = collision_point(xx, yy, obj, prec, notme);
if (col) {
ret_val = col;
other.raycast_hit_x = xx;
other.raycast_hit_y = yy;
break;
}
xx += lengthdir_x(1, tdir);
yy += lengthdir_y(1, tdir);
}
return ret_val;
}
Offline
Welcome to the forums, DJ Coco, and thanks for the submission.
We already have a couple of scripts that more-or-less do what this does. Please see:
Abusing forum power since 1986.
Offline
Oh, all right. Somehow I totally missed those, sorry.
Offline