B
Ben Hubble
Guest
Hello! I'm currently making a ray casting game (The illusion of 3D) and I've ran into a problem. I have made a script that draws whatever instance's sprite next to the game area (Where all the 2D stuff happens (i'll include a few pictures)). I've made a vision cone and whatever is in that vision cone is drawn to the screen, with adjusted size to make the illusion of 3D. I'll just show you my script:
The problem is that the sprite that I drew off to the left of my 2d game area, doesn't change size, but the even weirder part is that the left and top walls of the 2d game area change size! This is game breaking for me and any help would be appreciated!
If you would like, here is the code that draws my vision cone & gets the arguments for my script:
scr_get_length is this: (I didn't make this script, I got it off of GMC)
Check The Picture to understand better
Code:
///scr_draw_3d_obj(collision_line_length,how much to divide by,instance_id)
collLineLength = argument0;
divideby = argument1;
instance = argument2;
if(instance != undefined) {
sprite = draw_sprite(instance.sprite_index,instance.image_index,320,320);
sprite_xscale = collLineLength/divideby;
sprite_yscale = collLineLength/divideby;
sprite.image_xscale = sprite_xscale;
sprite.image_yscale = sprite_yscale;
}
If you would like, here is the code that draws my vision cone & gets the arguments for my script:
Code:
///Draw Vision Cone
draw_self();
draw_text(2,34,"FPS: " + string(fps));
direction = point_direction(x,y,mouse_x,mouse_y);
var length, lDir, rDir;
length = 250;
lDir = direction + 45;
rDir = direction - 45;
var ptnLeftX, pntLeftY, pntRightX, pntRightY;
pntLeftX = x + lengthdir_x(length, lDir);
pntLeftY = y + lengthdir_y(length, lDir);
pntRightX = x + lengthdir_x(length, rDir);
pntRightY = y + lengthdir_y(length, rDir);
draw_set_color(c_red);
draw_line(x, y, pntLeftX, pntLeftY);
draw_line(x, y, pntRightX, pntRightY);
draw_line(pntLeftX, pntLeftY, pntRightX, pntRightY);
draw_set_color(c_black);
for(i = lDir; i > rDir; i--)
{
len = scr_get_length(length, lDir, rDir, i);
rayCast = collision_line(x, y, x+lengthdir_x(len, i), y+lengthdir_y(len, i),obj_wall,false,true);
draw_line(x,y,x+lengthdir_x(len, i), y+lengthdir_y(len, i));
collisionLineLength = distance_to_point(x + lengthdir_x(len,i),y + lengthdir_y(len,i));
scr_draw_3d_obj(collisionLineLength,100,rayCast);
}
draw_text(2, 2, direction);
Code:
/// scr_get_length(rayLength, leftDir, rightDir, angle);
// NOTE: This assumes that the angle between leftDir and rightDir is 90 degrees
// it's fairly easy to adjust it however.
var angl;
angl = argument1 - argument3;
if(angl == argument1 || angl == argument2) return argument0;
return argument0 * sin(degtorad(45)) / sin(degtorad(180 - 45 - (90 - angl)));
Attachments
-
39.3 KB Views: 40