GMS 2 I need help with my gun object

Discussion in 'Programming' started by Zabicka, Aug 13, 2019 at 2:19 PM.

  1. Zabicka

    Zabicka Member

    Joined:
    Dec 14, 2018
    Posts:
    30
    I have a problem with my gun object, it works just fine when my character is facing right, but when he turns left and the gun is facing up or down, the gun flips to the oposite side, I just don't know how to fix it.


    Code:
    // Key input
    var key_up    = keyboard_check(vk_up);
    var key_left  = keyboard_check(vk_left);
    var key_down  = keyboard_check(vk_down);
    var key_right = keyboard_check(vk_right);
    
    // Hor & Ver input
    var hinput = key_right - key_left;
    var vinput = key_down - key_up;
    
    // Direction
    var pointdir = point_direction(0, 0, hinput, vinput);
    
    // Movement
    if (hinput != 0 || vinput != 0) {   
        x = target.x + lengthdir_x(8, pointdir);
        y = target.y + lengthdir_y(8, pointdir) - 8;
    } else {
        x = target.x + 8*target.facing; // Target is the player and Facing is player's direction (like var hinput)
        y = target.y - 8;
    }
    
    // Animation
    image_angle = pointdir;
    
    if (hinput != 0) {
        image_xscale = 1;
        image_yscale = hinput;
    } else {
        image_xscale = target.facing;
        image_yscale = 1;
    }
     

    Attached Files:

  2. YoSniper

    YoSniper Member

    Joined:
    Jun 24, 2016
    Posts:
    418
    Make sure the gun's image_xscale is the same as the player's.

    Then:
    Code:
    //Animation
    image_angle = pointdir;
    if image_xscale < 0 { //i.e. is -1
        image_angle += 180;
    }
     

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