Visuals not working accordingly with code, pls help!

Hey everyone, I have a problem with the visuals of my game, they are not working properly.
I am talking about my health bar. The healthbars color (little blue stripe at the end) stays were it is and the bullet hit from the enemy visual doesn't angle right, but I have used the same code as the player ones nd that one works fine.
I don't know how to fix this, but I have used some coding from a video and I have found no problems. I am pretty new to game maker studio 2. Maybe someone can look at it.

This is the link from the video:

this is my code (only the healthbar and bullet code otherwise this post will be to long):


code player:


max_health_ = 10;
health_ = max_health_;

// Alarm bullet
bullet_cooldown_ = room_speed / 4;
alarm[0] = bullet_cooldown_;

var solid_layer = layer_get_id("WallSolid");
layer_set_visible(solid_layer, debug_mode);

/// @description Create bullet
if alarm[0] <= 0 {
var dir = point_direction(x, y, mouse_x, mouse_y);
var flipped = (mouse_x < x)*2-1;
var gun_x = x-1*flipped
var x_offset = lengthdir_x(1, dir)
var y_offset = lengthdir_y(1, dir)

var bullet = instance_create_layer(gun_x+x_offset, y +y_offset, "instances", o_bullet);
bullet.direction = dir;
bullet.image_angle = dir;
alarm[0] = bullet_cooldown_;
}

code enemy:

/// @description Variables enemy
speed_ = [0, 0];
acceleration_ = 0.05;
max_speed_ = 5;
health_ = 4;

// Alarm bullet enemy
bullet_cooldown_ = room_speed / 2;
alarm[0] = bullet_cooldown_;

//States
MOVEMENT_ = 0;

/// @description Damage bullets
health_ -= 1;
instance_destroy(other);

var dir = other.direction;
speed_[h] = lengthdir_x(14, dir);
speed_[v] = lengthdir_y(14, dir);


state_ = MOVEMENT_

/// @description Soft colide
if point_in_rectangle(x, y, 0, 0, room_width, room_height) {
if x == other.x and y == other.y {
x += sign(other.id - id)
}
var dir = point_direction(other. x, other. y, x, y);
speed_[h] += lengthdir_x(.2, dir);
speed_[v] += lengthdir_y(.2, dir);
}

/// @description Movement State
// Move
if instance_exists(o_player) {
var dir = point_direction(x, y, o_player.x, o_player.y);
speed_[h] += lengthdir_x(acceleration_, dir);
speed_[v] += lengthdir_y(acceleration_, dir);
if point_distance(0, 0, speed_[h], speed_[v]) > max_speed_ {
var move_dir = point_direction(0, 0, speed_[h], speed_[v]);
speed_[h] = lengthdir_x(max_speed_, move_dir);
speed_[v] = lengthdir_y(max_speed_, move_dir);
}

if distance_to_object(o_player) < 60 {
enemy_fire_bullet();
}

// Create a bullet
enemy_fire_bullet();
}

move(speed_, 1);

bullet player:
// Move towards the mouse
speed = 15;
depth = -1;

var hit = instance_create_layer(x, y, "Instances", o_bullet_hit);
hit.image_angle = image_angle;

// Destroy bullet
instance_destroy();

image_speed = 0;
image_index = 1;

bullet enemy:

// Move towards the mouse
speed = 10;
depth = -1;

var hit = instance_create_layer(x, y, "Instances", o_bullet_hit_enemy);
hit.image_angle = image_angle;

// Destroy bullet
instance_destroy();

image_speed = 0;
image_index = 1;

bullet hit:
depth = -1;
instance_destroy();

bullet hit enemy:
depth = -1;
instance_destroy();


script: enemy_fire_bullet:

// Create a bullet
if alarm[0] <= 0 {
var dir = point_direction(x, y, o_player.x, o_player.y);
var x_offset = lengthdir_x(1, dir)
var y_offset = lengthdir_y(1, dir)

var bullet = instance_create_layer(x+x_offset, y+y_offset, "instances", o_bullet_enemy);
bullet.direction = dir;
alarm[0] = bullet_cooldown_;
}

healthbar:
draw_health_ = 0;
/// @description Taking damage
draw_self();

if !instance_exists(o_player) exit;

draw_health_ = lerp(draw_health_, o_player, .3);

draw_set_color(c_blue);
draw_rectangle(x+4, y+4, x+123*draw_health_ / o_player.max_health_, y+11, false);
draw_set_color(c_white);

script: move

///@param speed
///@param bounce
var speed_ = argument0;
var bounce_ = argument1;

// Horizontal
if (place_meeting(x+speed_[h], y, o_wall)) {
while (!place_meeting(x+sign(speed_[h]), y, o_wall)) {
x = x + sign(speed_[h]);
}
if bounce_ > 0 {
speed_[@ h] = -speed_[@h]*bounce_;
} else {
speed_[@ h] = 0;
}
}
x += speed_[h];

// Vertical
if (place_meeting(x, y+ speed_[v], o_wall)) {
while (!place_meeting(x, y+sign(speed_[v]), o_wall)) {
y = y + sign(speed_[v]);
}
if bounce_ > 0 {
speed_[@ v] = -speed_[@ v]*bounce_;
} else {
speed_[@ v] = 0;
}
}
y += speed_[v];
 

Attachments

Sorry, try:

You can follow the code step by step in the debugger and see what happens at keypoints in the code.
Thanks for the advice, but I think that because I have the trial version I can't do a whole lot in debugger mode. There are some buttons blocked from clicking, which I think I need
 
Top