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

Obj_bullet shoot from obj_shotgun?

S

SashoTAI

Guest
So I was making a platformer shooter and I was adding the gun (obj_shotgun) and made it follow the player. However when I try to make the bullet (obj_bullet) shoot from the shotgun, it just shoots horizontally from the mouse. Any ideas? Here is my bullet code. It's in the create event btw:
  1. //set up motion
  1. direction = point_direction(x, y, mouse_x, mouse_y);
  2. speed = 16;
  3. image_angle = direction;
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
if you shoot with mouse click, then:

[SHOOTGUN STEP EVENT]
Code:
if(mouse_check_button_pressed(mb_left))
{
    var bullet = instance_create_depth(x, y, ....);
    with(bullet)
    {
        direction = point_direction(other.x, other.y, mouse_x, mouse_y);
        speed = 16;
        image_angle = direction;
    }
}
PS: and remove the code you have from the bullet [CREATE EVENT] I just realized the bullet spawner was the shotgun... so put the code in the shotgun step event
 
S

SashoTAI

Guest
Post the code that creates the bullet.
  1. //shooting

  2. if mouse_check_button(mb_left) && cooldown_ < 1
  3. {
  4. instance_create_layer(mouse_x,mouse_y,"BulletsLayer", obj_bullet)
  5. cooldown_ = 10;
  6. }
  7. cooldown_ = cooldown_ - 1;
cooldown_ is a variable I made and set to 10 in the create event:
  1. //variables
  2. cooldown_ = 10;
 
S

SashoTAI

Guest
if you shoot with mouse click, then:

[SHOOTGUN STEP EVENT]
Code:
if(mouse_check_button_pressed(mb_left))
{
    var bullet = instance_create_depth(x, y, ....);
    with(bullet)
    {
        direction = point_direction(other.x, other.y, mouse_x, mouse_y);
        speed = 16;
        image_angle = direction;
    }
}
PS: and remove the code you have from the bullet [CREATE EVENT] I just realized the bullet spawner was the shotgun... so put the code in the shotgun step event
Thank you so much! It worked! I just changed the instance_create_depth to instance_create_layer and it worked perfectly! Thank you, again! I just need to work on a cooldown. I'll write again if anything goes wrong.
 
S

SashoTAI

Guest
Why are you surprised that the bullet is coming from the mouse when you specifically tell it to spawn there?
I did a tutorial from gamemaker and it told me to make it shoot with that code and it worked. Anyway, thanks for the help!
 
Top