• 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!

GML I want my collision_line, not to go through the walls.

GGJuanPabon

Member
Sorry in advance, my English is not native language. I want my collision_line, not to go through the walls. Because I don't want the enemy to detect the player behind a wall.

I am making an enemy type IA, if he detects me, he will be alerted, and 2 seconds later, if he is not out of range, he will follow me. But after doing so, I realized that collision_line crosses my wall and if it touches the player behind the wall, it will alert. There is no logic if I leave it that way.

Code:
collisionLineaAlert = 100;
endLineAlert = collisionLineaAlert * -image_xscale;
if (collision_line(x, y, x + endLineAlert, y, obj_Ground, false, false))
        {
            var col = collision_line(x, y, x + endLineAlert, y, obj_Ground, false, false)
             while (col)
            {
                collisionLineaAlert  -= 1;
            }
                       
        }
Then I was trying to reduce the size of the end of the line, but for some reason it seems an infinite loop is formed, and my game dies.

What I can do?

Thanks in advance.
 

chamaeleon

Member
Sorry in advance, my English is not native language. I want my collision_line, not to go through the walls. Because I don't want the enemy to detect the player behind a wall.

I am making an enemy type IA, if he detects me, he will be alerted, and 2 seconds later, if he is not out of range, he will follow me. But after doing so, I realized that collision_line crosses my wall and if it touches the player behind the wall, it will alert. There is no logic if I leave it that way.

Code:
collisionLineaAlert = 100;
endLineAlert = collisionLineaAlert * -image_xscale;
if (collision_line(x, y, x + endLineAlert, y, obj_Ground, false, false))
        {
            var col = collision_line(x, y, x + endLineAlert, y, obj_Ground, false, false)
             while (col)
            {
                collisionLineaAlert  -= 1;
            }
                      
        }
Then I was trying to reduce the size of the end of the line, but for some reason it seems an infinite loop is formed, and my game dies.

What I can do?

Thanks in advance.
Make all the types of objects have the same parent object and use collision_line_list, sorted by distance, and if the player is not the first thing in the list, there is a wall in the way. I'm sure there are other ways that works just as well, but this seems easy to test.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I wrote a script just for that
https://yal.cc/gamemaker-collision-line-point/
Code:
/// collision_line_point(x1, y1, x2, y2, obj, prec, notme)
var x1 = argument0;
var y1 = argument1;
var x2 = argument2;
var y2 = argument3;
var qi = argument4;
var qp = argument5;
var qn = argument6;
var rr, rx, ry;
rr = collision_line(x1, y1, x2, y2, qi, qp, qn);
rx = x2;
ry = y2;
if (rr != noone) {
   var p0 = 0;
   var p1 = 1;
   repeat (ceil(log2(point_distance(x1, y1, x2, y2))) + 1) {
       var np = p0 + (p1 - p0) * 0.5;
       var nx = x1 + (x2 - x1) * np;
       var ny = y1 + (y2 - y1) * np;
       var px = x1 + (x2 - x1) * p0;
       var py = y1 + (y2 - y1) * p0;
       var nr = collision_line(px, py, nx, ny, qi, qp, qn);
       if (nr != noone) {
           rr = nr;
           rx = nx;
           ry = ny;
           p1 = np;
       } else p0 = np;
   }
}
var r;
r[0] = rr;
r[1] = rx;
r[2] = ry;
return r;
 

GGJuanPabon

Member
Make all the types of objects have the same parent object and use collision_line_list, sorted by distance, and if the player is not the first thing in the list, there is a wall in the way. I'm sure there are other ways that works just as well, but this seems easy to test.
Thanks for your help, there is little information about that function, I will try to try.

I wrote a script just for that
https://yal.cc/gamemaker-collision-line-point/
undefined
Your solution looks interesting, I'm going to try, I mean, first I would have to study the use of arguments, because I don't know how it works in Game Maker, but I'll be testing. Thank you.
 
Top