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

collision line error...

A

AtLantiSs

Guest
Guys I'm using this code
Code:
///Check if it can see
if see = 1
{
if blocked = 0
{
if collision_line(x,y,target.x,target.y,obj_wall_basic,0,0)
{
blocked = 1;
soundoff = choose(0,1);
alarm[10] = room_speed*2;
}
}
}

if !collision_line(x,y,target.x,target.y,obj_wall_basic,0,0)
{
blocked = 0;
}
what it does is that it checks if the player is hiding behind a wall. If it is, then an alarm sets off, when the alarm is running, then the enemy no longer sees the player and walks off to its gaurding point.

Problem is, I can just walk up to a wall and just move my player very close to the wall, then the enemy acts like I'm hiding and the script runs and the enemy doesnt see me when I'm right in front of them!

Screenshots

Enemy sees me in this pic:


Bellow the enemy is right in front of me but the collision line isn't doing its job... (I already checked masks and collision masks, thats not the case)


 

obscene

Member
You probably need to set both collisiion functions "precise" values to true. Also your wall sprites need to have precise collision enabled.
 
A

AndrewFM

Guest
collision_line doesn't return a boolean. It returns an instance that the line collided with, or noone if no collision occurred.
 
At the beginning of the code, add this:
Code:
show_debug_message("see: " + string(see));
show_debug_message("blocked: " + string(blocked));
When you expect a collision and have issues, what do those say?
collision_line doesn't return a boolean. It returns an instance that the line collided with, or noone if no collision occurred.
True is anything > 0 and false is <= 0. Id's are always positive and noone is negative. It should still work.
Edit: better explanation... if statements read true and false like I explained above. The constant true == 1 and false == 0.
 
Last edited:
A

AtLantiSs

Guest
But that still doesn't fix this from happening the monsters don't see me even if im in front of them... What should happen is that if I'm behind a wall then their alarm counts down.
 
A

AtLantiSs

Guest
Blocked = 0 : the enemy object can see the player (collision_line(x,y,target.x,target.y,obj_wall_basic,0,0) is false for this to happen)
Blocked = 1: the enemy object cannot see the player because a wall is in the way (collision_line(x,y,target.x,target.y,obj_wall_basic,0,0) is true for this to happen)

However, when the player gets into some edge in a wall object, with still a wide open space where there SHOULDNT be a collision line returning to noone aka '0' aka false, the enemy no longer sees me.

It's probably a sprite problem
Here's the collision mask for the wall sprites

sprite_collision_mask(mysprite,0,0,0,103,0,252,0,0)

the wall is precise, I set the collisions to precise and still nothing
 

obscene

Member
Ditch sprite_collision_mask(mysprite,0,0,0,103,0,252,0,0).

Set the sprite to precise. Leave it on automatic so the pixel values are used as the mask. Make sure the collision line functions have a 1 in the precise fields. If this don't work, please copy and paste your new complete code and a screeshot of your sprite settings too if you aren't sure.
 
Blocked = 0 : the enemy object can see the player (collision_line(x,y,target.x,target.y,obj_wall_basic,0,0) is false for this to happen)
Blocked = 1: the enemy object cannot see the player because a wall is in the way (collision_line(x,y,target.x,target.y,obj_wall_basic,0,0) is true for this to happen)
Well from the code you have posted, it's not doing anything wrong. You have to set something like
Code:
if(blocked == 0){ image_blend = c_red; }
If you have code like that after your collision line code you should post it. That's why I asked what code runs when blocked = 0.

But check if what @obscene said works first.
 
A

AtLantiSs

Guest
The damn sprites! Got it working, yep it was the sprites + precisions. Thank you so much.
 
Top