Intro?
Ever wanted a way to check whether the line collides with an instance, pixel-by-pixel, without killing the framerate? Methods already exist, but most are not very efficient as the distance increases, some are not even efficient on small distances like 100px... This script can successfully cast 180 rays and keep an fps of 94 on my machine!
What is ray-tracing?
It's a process of following a ray (line), looking for information we're interested in. In this case, the ray is casted and is looking for a collision with an object specified.
How come your script is so "efficient"???
It creates multiple chunks of the ray, checks for each line is it colliding. If the line collides, it checks for each pixel for where the exact position is.
What's your script's performance?

This is a chart that shows my PC's performance using the script.
Left shows how many rays can be casted under what FPS, while drawing a primitive connecting each collision point.
Right shows the exact same, but without drawing the primitive.
900 Rays casted, each running an average of around 200 pixels in distance, doing it 12 times in one second with my script...
Same that, but with traditional way of ray-tracing takes 4-5 seconds!
You're lying!

In yer face!
UPDATE! Mirror (fixed gmk) by Newly Discovered:
http://host-a.net/JosephCh7/collision_raytracing.gmk
Run in debug mode, so you can watch your frame-rate!
First room of the example consists of one ray, looking for collision with the spinning object.
Left mouse click controls the position of the object.
Pressing Space bar switches from normal ray-tracing to my advanced ray-tracing.
Enter leads you to the next room...
Second room consists of an object controllable by left click.
It fires multiple rays, depending on resolution specified in the object.
It also draws a primitive connecting every collision point. It looks like that object's field of vision =D
Omg awesome, now, can you provide a script in txt format here please?... Maybe also tell us what each argument stands for?
/*
Args:
0 = angle at which the ray is running (real)
1 = object the ray is seeking (object name)
2 = maximum distance the ray will travel (real)
3 = chunk size. The length of lines the ray is divided (real)
*/
var i, a, _x, _y, _x2, _y2;
_x2=x
_y2=y
if collision_point(x,y,argument1,1,1)
{
off_x=x
off_y=y
exit;
}
for (i=1;i<argument2;i+=argument3)
{
_x=x+lengthdir_x(i,argument0)
_y=y+lengthdir_y(i,argument0)
if collision_line(_x2,_y2,_x,_y,argument1,1,1)
{
for (a=i-argument3;a<argument2;a+=1)
{
_x=x+lengthdir_x(a,argument0)
_y=y+lengthdir_y(a,argument0)
if collision_point(_x,_y,argument1,1,1)
{
off_x=_x
off_y=_y
return true;
exit;
}
}
}
_x2=_x
_y2=_y
}
off_x=_x
off_y=_y
return false;Cheers! =D
~ Krele
Edited by krele, 29 July 2010 - 11:16 PM.












