враги при столкновении с игроком создают объект obj_enemy_damage, и он создается, но урон не наносится
create:
Код
speed_enemy = 0.8;
phy_fixed_rotation = true;
hp = 3;
R = 150;
moveToPl = 0;
maxatksp = 30;
atksp = 0;
dmg = 1;
step:
Код
if moveToPl!=1 and obj_player.y<(self.y + R) and obj_player.y>(self.y - R) and obj_player.x<(self.x + R) and obj_player.x>(self.x - R){
moveToPl = 1;
}
if moveToPl == 1{
phy_position_x += sign(obj_player.x-x) * speed_enemy;
phy_position_y += sign(obj_player.y-y) * speed_enemy;
}
depth = -y;
if atksp!=maxatksp{
atksp+=1;
}
if hp<=0{
instance_create_depth(x,y,0,obj_enemy_death);
instance_destroy();
}
collision с obj_player:
Код
if atksp == maxatksp{
var damage_1 = instance_create_depth(x,y,0,obj_enemy_damage);
damage_1.creator = id;
atksp = 0;
}
У объекта obj_enemy_damage
create:
Код
knockb = 10;
creator = noone;
alarm[0] = 1;
collision с obj_player:
Код
if (other.id != creator){
other.hp -= creator.dmg;
var dir = point_direction(creator.x,creator.y, other.x, other.y);
var x_force = lengthdir_x(knockb, dir);
var y_force = lengthdir_y(knockb, dir);
with(other){
physics_apply_impulse(x,y,x_force,y_force);
}
}
alarm[0]:
и наконец у самого obj_player
create:Код
phy_fixed_rotation = true;
speed_player = 3;
image_speed = 0;
hp = 7;
maxatksp = 30;
atksp = 0;
dmg = 1;
step:
Код
var right_move = (keyboard_check(vk_right) or keyboard_check(ord("D")))
var left_move = (keyboard_check(vk_left) or keyboard_check(ord("A")))
var up_move = (keyboard_check(vk_up) or keyboard_check(ord("W")))
var down_move = (keyboard_check(vk_down) or keyboard_check(ord("S")))
if (up_move) {
phy_position_y -=speed_player;
sprite_index = player_sprites_up;
image_speed = 1;
}
if (down_move) {
phy_position_y +=speed_player;
sprite_index = player_sprites_down;
image_speed = 1;
}
if (right_move) {
phy_position_x +=speed_player;
sprite_index = player_sprites_right;
image_speed = 1;
}
if (left_move) {
phy_position_x -=speed_player;
sprite_index = player_sprites_left;
image_speed = 1;
}
if (!right_move and !left_move and !up_move and !down_move){
image_speed = 0;
image_index = 0;
}
depth = -y;
if hp<=0
instance_destroy();
if atksp!=maxatksp{
atksp+=1;
}
if keyboard_check_pressed(vk_space) and atksp==maxatksp{
if self.sprite_index == player_sprites_right{
var damage_1 = instance_create_depth(x+20,y, 0, obj_player_damage);
damage_1.creator = id;
}
if self.sprite_index == player_sprites_left{
var damage_1 = instance_create_depth(x-20,y, 0, obj_player_damage);
damage_1.creator = id;
}
if self.sprite_index == player_sprites_up{
var damage_1 = instance_create_depth(x,y-20, 0, obj_player_damage);
damage_1.creator = id;
}
if self.sprite_index == player_sprites_down{
var damage_1 = instance_create_depth(x,y+20, 0, obj_player_damage);
damage_1.creator = id;
}
atksp=0;
}
буду благодарна за помощь