• 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 [SOLVED]collision_line weird behaviour

jujubs

Member
I'm trying to do a hitscan weapon, and read elsewhere that collision_line was a good way to go about. So, I draw a line across the screen using this:

Code:
if(test> 0)
{
    draw_line(obj_player1.x+16,obj_player1.y-1,obj_player1.x+1000,obj_player1.y+1);
}
Once my player's state machine gets to "Shoot", it draws the line perfectly, going through the enemy that sits on the right.

However, when I try this with collision_line, like so:

Code:
with (obj_spawner)
    {
    collision_line(obj_player1.x+16,obj_player1.y-1,obj_player1.x+1000,obj_player1.y+1, id, true, false);
    instance_destroy();
}
...I ALWAYS get a hit on the enemy, even if I move my player up or down before shooting. Why? :(
 

DesArts

Member
There's no if statement
You never check if the collision happened.

The collision function returns the id of what it collided with, you never check if that id exists or not or anything.

Put if infront of it
 
Top