Collision_rectangle, collision_line not working

S

samyak

Guest
I might be missing something here, but it's not working. Here the calling instance shoots a bullet when the enemy is in collision with the given rectangle. If I do 'col= noone' instead of 'col!=noone', the bullet is shot normally.

Code:
shootcount= clamp(shootcount,-6,120);  shootcount++;

x2= x+lengthdir_x(270,image_angle+90);
y2= y+lengthdir_y(270,image_angle+90);



col= collision_rectangle(x-sprite_width/2,y2,x+sprite_width/2,y,b_common,false,true);

if col !=noone and shootcount>=121 and spd=0 and global.pause=-1 and state=0

{   
    instance_create_layer(x,y,l2,w_bullet);
 
    shootcount=-1;
 
 
}
 

mar_cuz

Member
You're clamping your shootcount to a max of 120 but then checking if it is above or equal to 121 to shoot when technically it would never reach 121. Could that be the issue?
 
S

samyak

Guest
You're clamping your shootcount to a max of 120 but then checking if it is above or equal to 121 to shoot when technically it would never reach 121. Could that be the issue?
It reaches 121. As I said , if I keep col=noone, then everything works normally
 
S

samyak

Guest
Don't invert the y. Try it like this:
Code:
collision_rectangle(x-sprite_width/2,y,x+sprite_width/2,y2,b_common,false,true);
Nope, didn't work .Actually I wanted collision_line, but collision_line isn't working too.
 
S

samyak

Guest
Don't invert the y. Try it like this:
Code:
collision_rectangle(x-sprite_width/2,y,x+sprite_width/2,y2,b_common,false,true);
Ok, I could pin-point the problem. Actually the object b_common is persistent, and it was carried over from the previous room. Collision_line somehow does not work on persistent objects. I don't know how to solve this problem though.
 
Top