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
-
92.8 KB Views: 7