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

GameMaker I need help with my gun object

Zabicka

Member
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;
}
 

Attachments

YoSniper

Member
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;
}
 
Top