Hi there,
I'm having a frustrating issue with getting enemy objects to be knocked back in the right direction when they have been attacked by the player (i.e. knocked to the left if the player is to the right and vice versa). They are currently being knocked to the right regardless of the position of the player.
When the attack button is pressed, a hitbox object is being created, which has the following code in the step event to detect for a collision with an enemy, deduct a health point, and store the direction from which the attack came:
And this is the code in the enemy object's begin step event which is triggered when it's health points reach 0, and handles the movement for the knockback effect:
For some reason the enemy is always being knocked to the right. What's frustrating is that I have another object with exactly the same code for a projectile weapon which works fine. What have I missed?!
Thanks for any suggestions
I'm having a frustrating issue with getting enemy objects to be knocked back in the right direction when they have been attacked by the player (i.e. knocked to the left if the player is to the right and vice versa). They are currently being knocked to the right regardless of the position of the player.
When the attack button is pressed, a hitbox object is being created, which has the following code in the step event to detect for a collision with an enemy, deduct a health point, and store the direction from which the attack came:
Code:
if (place_meeting(x,y,pshootable))
{
audio_play_sound(snhitenemy,30,false);
with (instance_place(x,y,pshootable))
{
hitfrom = other.direction;
hp--;
flash = 3;
}
}
Code:
if (hp <= 0)
{
audio_sound_pitch(sninfecteddie,random_range(0.5,1));
audio_play_sound(sninfecteddie,3,false);
with(instance_create_layer(x,y,layer,oinfecteddead))
{
direction = other.hitfrom;
hsp = lengthdir_x(3,direction);
vsp = vsp -1;
if (sign(hsp) != 0) image_xscale = sign(hsp) * other.size;
image_yscale = other.size;
}
instance_destroy();
}
Thanks for any suggestions