GML Flipping bullet on off center barrel?

Discussion in 'Programming' started by Annthoni, Aug 26, 2017.

  1. Annthoni

    Annthoni Member

    Joined:
    Aug 26, 2017
    Posts:
    4
    Im new to game maker 2, and well creating games in general, ive been following some tutorials and decided to be abit creative early on by designing a off center barrel gun for my sprite, when the bullets fire to the right they seem to match the barrel, but they dont when the sprite flips to the left, can anyone help with this?

    ///Create bullet
    var dir = point_direction(x, y, mouse_x, mouse_y);
    var xscale = (mouse_x > x)*2-1;
    var gun_x = x-4*xscale;
    var x_offset = lengthdir_x(30, dir);
    var y_offset = lengthdir_y(30, dir);

    instance_create_layer(gun_x+x_offset, y+y_offset, "Instances", o_bullet);
    this is the code ive been using
     
  2. dannyjenn

    dannyjenn Member

    Joined:
    Jul 29, 2017
    Posts:
    568
    Are you sure you have both sprites' origins set correctly?
     
  3. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,166
    so i can't answer this question without having more information. Let me ask you this, where is the origin on the bullet sprite, and where is the origin on the gun sprite?
     
  4. Annthoni

    Annthoni Member

    Joined:
    Aug 26, 2017
    Posts:
    4
    I'm not quite sure, this is my first time making a game, been following along the YouTube tutorials, how would I find the origins?
     
  5. Annthoni

    Annthoni Member

    Joined:
    Aug 26, 2017
    Posts:
    4
    I used custom placement rather than the presets.
     
  6. Zhanghua

    Zhanghua Member

    Joined:
    Aug 3, 2017
    Posts:
    167
    you need update the direction in step event
     
  7. Annthoni

    Annthoni Member

    Joined:
    Aug 26, 2017
    Posts:
    4
    How would I flip the direction so that it would mirror left with right in the step? The bullets are aligned when the sprite fires right, they misalign when the sprite image flips to face left.
     
  8. Jakylgamer

    Jakylgamer Member

    Joined:
    Jun 27, 2016
    Posts:
    510
    assuming the bullets are being rotated and the sprites origin offset isn't centered , try flipping the yscale value of the bullet when mouse is < x
    example:
    Code:
    var bullet = instance_create_layer(x,y,layer,obj_bullet);
    if mouse_x < x {
       bullet.image_yscale = -1;
    } else {
       bullet.image_yscale = 1;
    }
    
     

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