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

Bullet collides but not at the same time

Megax60

Member
i set a certain type of bullet stop when it collides with a wall, but for some reason in the next step its not colliding with it, this happens randomly but i never use rng(except for visual effects)

obj_bullet step event:
Code:
var block;
block = instance_place(x,y,obj_solid);
if (block != noone){
    //Irrelevant stuff
    if stick{
        speed = 0;
    }
}
Timeline step 390:
Code:
///Warn the player
var check_bullet = 0;
for (i = 0; i < array_length_1d(bull);i++){
    with bull[i]{ //Loop through all bullets
        if !place_meeting(x,y,obj_solid){ //If at least one of them is not stuck in the wall, repeat
            with other{
                check_bullet++;
            }
        }
    }
}
if check_bullet > 0{ //If one or more bullets aren't stuck in the wall
    timeline_position--;
}else{
    for (i = 0; i < array_length_1d(bull);i++){
        with bull[i]{ //Loop through all bullets
            effect_create_above(ef_explosion,x+128,y,3,c_green); //this is temporal, bullet its supposed to shake
            direction += 180; //Point to where the bullet came from, the boss
        }
    }
}
in the step 450 of the timeline, it adds speed to all the bullets, but sometimes that doesn't happen, because if at least one of the bullets its not colliding with the wall, step 390 will repeat.

what happens is that, a bullet collides with the wall, and therefore, sets its speed to 0, but sometimes (this is the problem) it "unstucks" itself from the wall, floating in the air with 0 speed

i already tried removing the direction += 180, but thats not the problem
 

TsukaYuriko

☄️
Forum Staff
Moderator
So we're dealing with Schrödinger's bullet here? :p

Is obj_solid actually marked as solid? If it is, it may be resetting the bullets' positions to where they were the previous step, therefore "unstucking" them.

Try outputting the bullets' coordinates when they initially collide with the wall, as well as every Step thereafter. Does their position actually change? Does anything else that affects the collision mask change, like their sprite, subimage, mask, rotation, scaling...?


I'll take a shot in the dark and guess that you're setting image_angle to direction somewhere, which messes with the collision mask. What do I get if I'm right?
 

Megax60

Member
So we're dealing with Schrödinger's bullet here? :p

Is obj_solid actually marked as solid? If it is, it may be resetting the bullets' positions to where they were the previous step, therefore "unstucking" them.

Try outputting the bullets' coordinates when they initially collide with the wall, as well as every Step thereafter. Does their position actually change? Does anything else that affects the collision mask change, like their sprite, subimage, mask, rotation, scaling...?


I'll take a shot in the dark and guess that you're setting image_angle to direction somewhere, which messes with the collision mask. What do I get if I'm right?
I fixed it already but thanks, i set the speed = 0 in the end step, thats really weird, i still dont dont understand
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
I wouldn't call it fixed unless I understand both the cause and the solution. That's what makes the difference between writing off another "what the inhale was that" moment and learning. Your call, though.
 

Megax60

Member
I wouldn't call it fixed unless I understand both the cause and the solution. That's what makes the difference between writing off another "what the inhale was that" moment and learning. Your call, though.
Wait a second..... Now i get it! The bullet width is 4, and if speed is bigger than sprite_width, image_xscale will increase, in the begin of "step event" increases its image_xscale, in the end of the normal step image_xscale returns to 1, thats why changing speed = 0 to the end step fixes it
 

TsukaYuriko

☄️
Forum Staff
Moderator
Let me guess, the changing of image_xscale was part of "Irrelevant stuff"? That would be a nice point in case not to dismiss any line of code as being a potential culprit.

Anyway, I'm unsure if my rambling contributed to getting this resolved in any way whatsoever, but I'm glad it worked out for you in the end. :)
 

Megax60

Member
Let me guess, the changing of image_xscale was part of "Irrelevant stuff"? That would be a nice point in case not to dismiss any line of code as being a potential culprit.

Anyway, I'm unsure if my rambling contributed to getting this resolved in any way whatsoever, but I'm glad it worked out for you in the end. :)
Yea, your mention of the mask change helped, and no, the "irrelevant stuff" its destroy if colliding with certain type of block

The change of the image_xscale its at the very begging
 
Top