GM:S 1.4 [SOLVED]Shooting from tip/barrel of gun

Discussion in 'Programming' started by mateus souza, Jun 14, 2019.

  1. mateus souza

    mateus souza Member

    Joined:
    Jun 14, 2019
    Posts:
    3
    hello, I'm doing a top down project, however no matter what I do the bullet keeps coming out of the gun barrel, could anyone help me? I'm learning to use the game maker yet and I do not know some basic things.

    my sprite = x=128 y= 85
    origin = x=40 y=49
    gun tip = x=119 y=62

    global mouse left button =

    if (!fire){
    fire = true
    alarm[0] = cooldown;
    instance_create(x+lengthdir_x(77,image_angle),y+lengthdir_y(77,image_angle),obj_bullet);
    } sprite.png shooting.png playershoterror.png
     
  2. Fat_Man3468800

    Fat_Man3468800 Member

    Joined:
    Jun 22, 2016
    Posts:
    487
    Sounds about right, unless that's not what you want, in which case you should probably tell what you want it to do instead.

    3rd image: Oh wow, turns out it isn't coming from the barrel, seems more like from the center of the player sprite.

    Perhaps some clarifications on what you want exactly might help others help you?

    Anyways, for now I'll assume you want your bullets to come out from the barrel. If that's the case, try finding the coordinates of the barrel relative to the origins from the sprite editor, and use those coordinates to create your bullets (relative to the player as well of course).

    Hope I helped :)
     
    mateus souza likes this.
  3. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,034
    By chance, I happened to just be posting this diagram in another thread, but it will help you out as well:
    [​IMG]
     
    mateus souza likes this.
  4. mateus souza

    mateus souza Member

    Joined:
    Jun 14, 2019
    Posts:
    3
    I need the shot to come out of the gun barrel but I can not do it, I tried to use the diagram but I can not understand it, I tried it in several ways but it still did not work. ,:(
     
  5. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,733
    Your code is fine, just offset the image_angle by a few degrees, eg:

    Code:
    var_x = x + lengthdir_x(77, image_angle - 10);
    var_y = y + lengthdir_y(77, image_angle - 10);
    instance_create(_x, _y, obj_Bullet);
    If that's not correct, just change the "10" value for 8, or 15 or whatever works. :)
     
    mateus souza likes this.
  6. mateus souza

    mateus souza Member

    Joined:
    Jun 14, 2019
    Posts:
    3
    OWWWWWWW THANK YOU, it's more complicated than I thought, I would not be able to figure it out by myself, THANK YOU again,Now I can sleep peacefully :).
    solved.png
     
    Last edited: Jun 14, 2019
    Nocturne likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice