• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

SOLVED Hi. My space ship and lasers are not colliding with and destroying the asteroids.

SlFinn

Member
Hi. I have triple checked my code for the collision of my ships and lasers with the asteroids, and destruction of the asteroids. There isn't anything wrong with it that i can see.
The asteroids themselves seem to be floating on top of the space ships and lasers, as if they are on a layer on top of the ships and lasers, and are not on the same layer. I am unsure how to fix this or exactly what is wrong.

As you can see below, the asteroid just floats over the purple ship, unaffected by the lasers or the presence of the ship itself. Is there a way to fix this? Please help me if you can.


1601648867455.png
 

SlFinn

Member
Here is my code for the obj_asteroid and the lasers....please help if you can.

obj_asteroid Create Event:

GML:
GML:

sprite_index = choose(spr_asteroid_small, spr_asteroid_med);



direction = irandom_range(0,359);

image_angle =irandom_range(0,359);



speed = 2;
obj_asteroid Step Event:

Code:
Code:

y+=speed;



image_angle += 1;



move_wrap(true,true,sprite_width/2);
obj_allyship; asteroid collision event:

Code:
Code:

instance_destroy();



repeat(7) {

instance_create_layer(x, y, "Instances", obj_debris);

}

obj_player; asteroid collision event:



Code:

instance_destroy();



repeat(7) {

instance_create_layer(x, y, "Instances", obj_debris);

}
obj_laserbullet; asteroid collision event:

Code:
instance_destroy();



with(other) {

instance_destroy();



if(sprite_index == spr_asteroid_med) {

repeat(2) {

var new_asteroid = instance_create_layer(x, y, "Instances", obj_asteroid);

new_asteroid.sprite_index = spr_asteroid_small

}

}

else if(sprite_index == spr_asteroid_small) {

repeat(7) {

instance_create_layer(x, y, "Instances", obj_debris);



}

}

}
obj_allybullet; asteroid collision event:


Code:
instance_destroy();



with(other) {

instance_destroy();



if(sprite_index == spr_asteroid_med) {

repeat(2) {

var new_asteroid = instance_create_layer(x, y, "Instances", obj_asteroid);

new_asteroid.sprite_index = spr_asteroid_small

}

}

else if(sprite_index == spr_asteroid_small) {

repeat(7) {

instance_create_layer(x, y, "Instances", obj_debris);

}

}

}
obj_debris Create Event:

Code:
direction = irandom_range(0,356);

speed = 0.7;
obj_debris Step Event:

Code:
image_alpha -= 0.01;

if(image_alpha <= 0) {

instance_destroy();

}
Please help me figure out the reason why the asteroids are not being destroyed by the lasers, why there is no collision. I will really appreciate it.
 
Last edited:
  • Like
Reactions: Rob

Rob

Member
Check the collision mask for your sprites. I just discovered that the square sprites I just made have a 1x1 pixel collision on "automatic" and "full image". I had to set to manual to set the collision mask correctly.
 

SlFinn

Member
Check the collision mask for your sprites. I just discovered that the square sprites I just made have a 1x1 pixel collision on "automatic" and "full image". I had to set to manual to set the collision mask correctly.
Thank you Rob. I tried it but the asteroids are still not registering the lasers or spaceships, and no collision is happening. I still think it is because the asteroids are on a layer on top of the layer the ships and lasers are on. However when i look in the room inspector there's only one instance layer. So I am very confused. But thanks for the advice.
 

chamaeleon

Member
Thank you Rob. I tried it but the asteroids are still not registering the lasers or spaceships, and no collision is happening. I still think it is because the asteroids are on a layer on top of the layer the ships and lasers are on. However when i look in the room inspector there's only one instance layer. So I am very confused. But thanks for the advice.
Layers are not relevant for collision testing. Bounding boxes, sprite masks, etc, are. The depth at which the instance is does not factor into it.
 

SlFinn

Member
Layers are not relevant for collision testing. Bounding boxes, sprite masks, etc, are. The depth at which the instance is does not factor into it.
I have no idea what i am doing wrong then. If it is the code, i got a lot of it from the space rocks game maker tutorial, so it should be working, right? Anyway thanks for telling me but now i have no lead on what could be causing this problem. I have been researching possible solutions and testing them for three days now, but i obviously haven't thought of everything i guess.
 

chamaeleon

Member
I have no idea what i am doing wrong then. If it is the code, i got a lot of it from the space rocks game maker tutorial, so it should be working, right? Anyway thanks for telling me but now i have no lead on what could be causing this problem. I have been researching possible solutions and testing them for three days now, but i obviously haven't thought of everything i guess.
You may need to start using the debug options at your disposal. Breakpoints and the debugger, show_debug_message() at various points in the code (beginning of events or scripts to ensure they start execution, before and inside if statements with relevant variables to determine which condition may not apply as expected.
 

SlFinn

Member
You may need to start using the debug options at your disposal. Breakpoints and the debugger, show_debug_message() at various points in the code (beginning of events or scripts to ensure they start execution, before and inside if statements with relevant variables to determine which condition may not apply as expected.
ok, thanks, i'll do that then. At least i can see if the problem is really in my code this way.
 
Top