• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

draw line up to specific point

Hi all,

I'm trying to draw a line up to the point of meeting a specific object.

The code I made snaps to the x and y coordinates of the wall it points to.. but I want the line to be drawn pointing to the mouse_x,y coordinates up until it meets the wall.
Example.png


GML:
//Create Event:

X = xstart;
Y = ystart;

randomize();
X2 = mouse_x+choose(-3, -2, -1, 0, 1, 2, 3);
Y2 = mouse_y+choose(-3, -2, -1, 0, 1, 2, 3);

Direction = point_direction(X, Y, X2, Y2);




//Draw Event:
X2 = lengthdir_x(1000, Direction);
Y2 = lengthdir_y(1000, Direction);

if collision_line(X, Y, X2, Y2, objWall, true, true) {
        with (collision_line(X, Y, X2, Y2, objWall, true, true)) {
                other.X2 = id.x;
                other.Y2 = id.y;
            };
    };
    
draw_line_color(X, Y, X2, Y2, c_yellow, c_yellow);
 

poliver

Member
1. You could flip the sprite origin to the other side.

2. You could check which direction the line is coming from and then shorten it when drawing by adjusting the X coordinate. Same applies for Y coordinates if you're pointing at the ceiling for example.

Also if you'd set your origin to center instead of topleft it would be easier to account for all the directions.
 
Last edited:
Top