Legacy GM Vision Cone Problem

B

Ben Hubble

Guest
Screenshot (9).png Screenshot (10).png Hello, right now i'm making a ray casting game (the illusion of 3D) but I've run into a problem and i'm not able to do myself. Basically, (This is all in the 2D room) I've got my 90 degree vision cone coming out like a triangle from my player. I've done this by drawing 3 lines. Then I send a collision_line across each degree of the vision cone using lengthdir_x and lengthdir_y, that's my problem. I'll show you my code:
Draw Event:
Code:
///Draw Vision Cone
draw_self();
direction = point_direction(x, y, mouse_x, mouse_y);

lineLeftPos = direction - 45;
lineRightPos = direction + 45;

leftLine = draw_line(x,y,x + lengthdir_x(250,lineLeftPos),y + lengthdir_y(250,lineLeftPos));
rightLine = draw_line(x,y,x + lengthdir_x(250,lineRightPos),y + lengthdir_y(250,lineRightPos));
topLine = draw_line(x + lengthdir_x(250,lineLeftPos),y + lengthdir_y(250,lineLeftPos),x + lengthdir_x(250,lineRightPos),y + lengthdir_y(250,lineRightPos));

var i;
for(i = lineLeftPos; i < lineRightPos; i++)
{
rayCast = collision_line(x,y,x + lengthdir_x(250,i),y + lengthdir_y(250,i),obj_wall,false,true);
draw_line(x,y,x + lengthdir_x(250,i),y + lengthdir_y(250,i));
draw_text(32,32,rayCast);

scr_draw_3d_obj(rayCast);
}
My problem is, since my vision cone is a triangle, the collision_lines stick out past the base of the triangle (Furthest away from the player). I don't have a clue how to get the collision_lines to stop once it reaches the end of the triangle. I've put a few pictures to help you understand (The first picture shows that the lines are meant to stop at the triangle base, the second picture show where the lines actually go)
 
B

bojack29

Guest
Why dont you just use the point_in_triangle function?

Its far more optimized to find a point in range than doing endless collision lines.
 

Genetix

Member
Or if you don't mind doing it - you could hard code each of the collision lines with an appropriate length... Sounds like a pain, but you may not one for each degree - you could cut it down to 10 or so.
 
B

Ben Hubble

Guest
Thank you, this is exactly what I need, (although I kinda get lost on what it's doing a bit, ok a lot)
 
Top