Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Usage: if (target_in_sight(obj))
- //It's laggy sometimes but it works
- var xx,yy,zz,faceDir,facePitch,ii,target,seen;
- target=argument0;
- xx=x;
- yy=y;
- zz=z+(height-4);
- faceDir=point_direction(x,y,target.x,target.y);
- facePitch=-point_direction_3d(x,y,z+(height-4),target.x,target.y,target.z+random(target.height));
- seen=false;
- //Works as is, don't increase range or lower length, or you'll murder your memory
- repeat (global.drawRange/1.1)
- {
- xx+=lengthdir_x(1,faceDir);
- yy+=lengthdir_y(1,faceDir);
- zz+=lengthdir_y(1,facePitch);
- ii=collision_point(xx,yy,obj_wall_basic,true,false);
- if !(ii==noone)
- {
- if (zz>=ii.z2 && zz<=ii.z1)
- {
- break
- }
- else
- {
- continue
- }
- }
- ii=collision_point(xx,yy,obj_wall_high_basic,true,false);
- if !(ii==noone)
- {
- if (zz>=ii.z2 && zz<=ii.z1)
- {
- break
- }
- else
- {
- continue
- }
- }
- ii=collision_point(xx,yy,obj_wall_low_basic,true,false);
- if !(ii==noone)
- {
- if (zz>=ii.z2 && zz<=ii.z1)
- {
- break
- }
- else
- {
- continue
- }
- }
- ii=collision_point(xx,yy,obj_floor_basic,true,false);
- if !(ii==noone)
- {
- if (zz>=ii.z && zz<=ii.z)
- {
- break
- }
- else
- {
- continue
- }
- }
- ii=collision_point(xx,yy,obj_ceiling_basic,true,false);
- if !(ii==noone)
- {
- if (zz>=ii.z && zz<=ii.z)
- {
- break
- }
- else
- {
- continue
- }
- }
- ii=collision_point(xx,yy,obj_block_basic,true,false);
- if !(ii==noone)
- {
- if (zz>=ii.z2 && zz<=ii.z1)
- {
- break
- }
- else
- {
- continue
- }
- }
- ii=collision_point(xx,yy,obj_slope_basic,true,false);
- if !(ii==noone)
- {
- var point;
- if (ii.slopeDir==90)
- {
- point=ii.z1+(point_distance(x,y,ii.x,y)/1.36);
- }
- if (ii.slopeDir==180)
- {
- point=ii.z1-point_distance(x,y,ii.x,y);
- }
- if (zz>=point && zz<=point)
- {
- break
- }
- else
- {
- continue
- }
- }
- ii=collision_point(xx,yy,target,true,false)
- if !(ii==noone)
- {
- if (zz>=ii.z && zz<=(ii.z+ii.height))
- {
- seen=true;
- break
- }
- else
- {
- continue
- }
- }
- }
- debugX=xx;
- debugY=yy;
- debugZ=zz;
- return (seen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement