shooting in gamemaker

wazzup guys
im looking for a way for my character to to shoot but i cant find a way to have the bullet with the character.So now whenever i shoot the bullet is somewhere else

Comments

  • So this comes down to where you are creating the bullet.

    I would do this from your player object in the step event. I'm not exactly sure what you're using for input (I'm guessing mouse) so adapt as needed.

    if( mouse_check_button_pressed( mb_left))
    {
       var bullet = instance_create( x, y, obj_bullet);
       bullet.direction = point_direction( x, y, mouse_x, mouse_y);
       bullet.speed = 5;   
    }


    Since in this case I was creating the bullet using the player object I could just use x and y as those would be the player's x and y coords.

    If I was creating the bullets and I wanted them to be at the player, but I was not creating them in the player I would need to find the player and then create the bullets using its x and y.

    var player = instance_find( obj_player, 0);
    var bullet = instance_create( player.x, player.y, obj_bullet);


    BTW I would recommend using one of the Game Maker help threads http://www.makegamessa.com/discussion/743/game-maker-some-questions

    It means there are less threads and provides a centralized resource for people looking at similar issues ;)

    Hope this helps, and looking forward to seeing your prototype.
    Thanked by 1cooldudue
  • Hey, not sure how new you are to Game Maker, so hopefully I'm not giving you resources way below your skill level, but Tom Francis (he made Gunpoint) is running a series of Game Maker tutorials (for people with absolutely no experience) over on teh Youtubez. He definitely covers how to make shooting happen, the rest might also come in handy :)
    Thanked by 1cooldudue
  • @karuji how would i make the bullet point in the direction the character is pointing
  • @Brondin excellent resource. I'm probably better than Tom with GM and I still really enjoy those videos.

    @Cooldudue that depends on how you are determining your character's direction, and how many directions there are. Are you using arrow keys for top down 8 directional movement? Are you doing a platformer where you can only face two directions?

    If you're assigning a direction to your player via the direction variable then it would simply be

    bullet.direction = direction


    But you'll need to tell me how you are doing you're player's direction and movement for me to give you what you need ;)
  • edited
    Also, if you wan the sprite to face the direction it's moving:

    Bullet's Step Event:
    image_angle = direction
  • @karuji my player is moving in four directions but when I move he is not the shooter
  • @cooldudue any chance you upload a build (single runtime exe, or zip) of the game somewhere? Would be a lot easier to give feedback :)

    Also you should really do the videos @Brondin linked they will help you immensely with using GM.
  • what doe this mean?


    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Create Event
    for object obj_bullet:

    Push :: Execution Error - Variable Get 100143.bullet_direction(100001, -2147483648)
    at gml_Object_obj_bullet_CreateEvent_1 (line 2) - __b__ = action_if_variable( bullet_direction, 1, 0 );
    ############################################################################################
  • This is normally with trying to reference an object that no longer exists, or an incorrect variable name.

    BTW have you checked out the videos that Tom Francis posted, and Brondin linked?
  • I'd recommend doing all the tutorials and then demos which come with game maker studio pre-packaged,
    you can get it when you say start a new project and look at selecting top menu tabs "Tutorials"..etc.

    Demo's:
    Scrolling shooter part1 and 2.
    Also check the demo:
    Surfaces_Part1 - much more complex but you will learn alot and it comes built in with shooting example for top down games. However, this tutorial demo's collision I do not recommend.
  • @Boysano

    i already figured this out by myself
Sign In or Register to comment.