Lee Summerville
Member
I'm using GameMaker Studio 2 and I'm having an issue getting a bullet to shoot left and right with a character. I haven't used GM for over a year, but the instance_create used to be pretty easy to use. As well as some of the DnD functions that they have now taken out which used to be super easy and quick to use - especially when teaching the software to students.
But now, I just can't seem to get this function to work the way I need it to.
I managed to find online and get the below code to work - however when I press the space bar to shoot a bullet, it also creates a second instance of the bullet on the screen which stays stationary on the screen. I cannot figure out why.
I've tried doing this multiple ways with the result of the bullet either shooing in only one direction, or it just stays in the one place on the screen, then whenever I press the spacebar again, it puts another bullet, then another, and so on each time I press the spacebar to shoot.
In my obj_bullet - I have the instance of the bullet being destroyed when it leaves the room or when it collides with the wall or enemy. This does not remove the stationary bullets from the screen during game play.
Any suggestions would be greatly appreciated.!!!
The following is located in my obj_player
EVENT = Key Press - Space
//Shooting Bullet
if keyboard_check(vk_left)
{
newBullet=instance_create_layer(x,y,"Bullet",obj_bullet);
newBullet.direction=obj_player.direction;
newBullet.speed=15;
x -=8;
direction=180;
}
if keyboard_check(vk_right)
{
newBullet=instance_create_layer(x,y,"Bullet",obj_bullet);
newBullet.direction=obj_player.direction;
newBullet.speed=15;
x +=8;
direction=0;
}
But now, I just can't seem to get this function to work the way I need it to.
I managed to find online and get the below code to work - however when I press the space bar to shoot a bullet, it also creates a second instance of the bullet on the screen which stays stationary on the screen. I cannot figure out why.
I've tried doing this multiple ways with the result of the bullet either shooing in only one direction, or it just stays in the one place on the screen, then whenever I press the spacebar again, it puts another bullet, then another, and so on each time I press the spacebar to shoot.
In my obj_bullet - I have the instance of the bullet being destroyed when it leaves the room or when it collides with the wall or enemy. This does not remove the stationary bullets from the screen during game play.
Any suggestions would be greatly appreciated.!!!
The following is located in my obj_player
EVENT = Key Press - Space
//Shooting Bullet
if keyboard_check(vk_left)
{
newBullet=instance_create_layer(x,y,"Bullet",obj_bullet);
newBullet.direction=obj_player.direction;
newBullet.speed=15;
x -=8;
direction=180;
}
if keyboard_check(vk_right)
{
newBullet=instance_create_layer(x,y,"Bullet",obj_bullet);
newBullet.direction=obj_player.direction;
newBullet.speed=15;
x +=8;
direction=0;
}