B
Ben Hubble
Guest
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:
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)
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);
}