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

Bullets not appearing

A

Alpha128

Guest
Hello all.
I am making my game via the Gamemaker 2 Shaun Spalding tutorial with minor adjustments for my liking. I have just finished it making the spawners but when I ran it, no bullets were shooting out like they have been for most of the project, in fact its only been a problem until now. I have tried moving the BulletsLayer to the very top but nothings changed. I am new, so help is very appreciated.

- A nub
 
A

Alpha128

Guest
Please post all relevant code.
Code:
//Player Code:Step
// Shoot Code
if (mouse_check_button(mb_left)) & (cooldown < 1)
{
    instance_create_layer(x,y,"BulletsLayer",obj_bullet)
    cooldown = 10;
}   

cooldown = cooldown - 1;
Code:
//Bullet Code:Create
//Set Up Motion
direction = point_direction(x, y, mouse_x, mouse_y);
direction = direction + random_range(-4, 4)
speed = 16;
image_angle = direction
 

NightFrost

Member
This
Code:
if (mouse_check_button(mb_left)) & (cooldown < 1)
should be
Code:
if (mouse_check_button(mb_left)) && (cooldown < 1)
 
A

Alpha128

Guest
This
Code:
if (mouse_check_button(mb_left)) & (cooldown < 1)
should be
Code:
if (mouse_check_button(mb_left)) && (cooldown < 1)
Oh yes that. Oops, my bad, but still doesn't fix the problem.

P.S been on holiday so I couldn't reply for a long time
 

Slyddar

Member
Is there any collision code with the bullets in any object, possibly the player, where they may be getting destroyed as soon as they spawn.

You can add something like this to the section that spawns them, and see if you are actually spawning, and if different id's are showing, indicating multiple spawns.
Code:
var inst = instance_create_layer(x, y, "Bulletslayer", obj_bullet);
show_debug_message(inst.id);
cooldown = 10;
 
A

Alpha128

Guest
Is there any collision code with the bullets in any object, possibly the player, where they may be getting destroyed as soon as they spawn.

You can add something like this to the section that spawns them, and see if you are actually spawning, and if different id's are showing, indicating multiple spawns.
Code:
var inst = instance_create_layer(x, y, "Bulletslayer", obj_bullet);
show_debug_message(inst.id);
cooldown = 10;
Where does it show the ID's?
 

Slyddar

Member
I just see the number 10008 counting up by 1 really fast and even when I'm not clicking.
That is the id of the instance that is being created. It should be incrementing by 1 every time you shoot. If it's just incrementing all the time, it could mean the instance is being created and then being destroyed instantly, and then another one is being created and destroyed. The id is just a number GMS assigns to each object created, and it's assigned sequentially.

So do you have a collision event with the bullet somewhere else in your code? Is it incrementing only when you click to shoot, or all the time when you shoot, or just all the time?
 
A

Alpha128

Guest
That is the id of the instance that is being created. It should be incrementing by 1 every time you shoot. If it's just incrementing all the time, it could mean the instance is being created and then being destroyed instantly, and then another one is being created and destroyed. The id is just a number GMS assigns to each object created, and it's assigned sequentially.

So do you have a collision event with the bullet somewhere else in your code? Is it incrementing only when you click to shoot, or all the time when you shoot, or just all the time?
But its counting up faster than my fire rate. Heres some other collision stuff anyway:
Code:
with(other)
{
    hep -= 1; //take damage
    if (hep <= 0)
    {
        with (obj_score) thescore = thescore + 5;
        audio_sound_pitch(snd_death1, random_range(0.8,1.2))
        audio_play_sound(snd_death1,0,0);
        instance_destroy();//die when out of health
    }
    instance_destroy(other); //destroy the bullet
}
 

Slyddar

Member
But its counting up faster than my fire rate.
In that case it's being destroyed before it can move. Comment out some of your instance_destroy lines and see if you can make the bullet fire again.

Which object/event is running that collision code?
 
A

Alpha128

Guest
In that case it's being destroyed before it can move. Comment out some of your instance_destroy lines and see if you can make the bullet fire again.

Which object/event is running that collision code?
The bullet is running that code and it is a step event.
 

Slyddar

Member
The bullet is running that code and it is a step event.
If it's in the step event, it is running every step of the game, so 30 or 60 times a second, depending on your game speed.

You will want to have the collision code in a Collision event. Create a Collision event in obj_bullet, with an enemy. Then remove it from the step and put the code in the collision event i.e.
Code:
//collision event in obj_bullet with obj_enemy
with(other)
{
   hep -= 1; //take damage
   if (hep <= 0)
   {
       with (obj_score) thescore = thescore + 5;
       audio_sound_pitch(snd_death1, random_range(0.8,1.2))
       audio_play_sound(snd_death1,0,0);
       instance_destroy();//die when out of health
   }
   instance_destroy(other); //destroy the bullet
}
 
A

Alpha128

Guest
If it's in the step event, it is running every step of the game, so 30 or 60 times a second, depending on your game speed.

You will want to have the collision code in a Collision event. Create a Collision event in obj_bullet, with an enemy. Then remove it from the step and put the code in the collision event i.e.
Code:
//collision event in obj_bullet with obj_enemy
with(other)
{
   hep -= 1; //take damage
   if (hep <= 0)
   {
       with (obj_score) thescore = thescore + 5;
       audio_sound_pitch(snd_death1, random_range(0.8,1.2))
       audio_play_sound(snd_death1,0,0);
       instance_destroy();//die when out of health
   }
   instance_destroy(other); //destroy the bullet
}
Oh oops, I meant to say it was a collision event. Sorry!
 
Top