Lately I have been having issues with implementing a knockback code for a particular type enemy that carries a shield and can only be attacked from behind. When performing an attack on the enemy's shield the player is suppose to be slightly pushed back from the strike. However, when implementing the code there is zero reaction from the player object not even the slightest nudge. I have tried to implement a Place_meeting on the sheild's hitbox as well as a sign variable on the hsp movement but I cannot figure what i going on.
**It should be noted that the player object is functioning on a Finite State Machine and the knockback code is currently in the attack script where the player strikes a object (in this case a shield) it should slightly push back the player.
**It should be noted that the player object is functioning on a Finite State Machine and the knockback code is currently in the attack script where the player strikes a object (in this case a shield) it should slightly push back the player.
Code:
///scr_Player_Attack
//Input Script
scr_Player_Input();
vsp = vsp + grv
//Horizontal Collision
if place_meeting(x+hsp,y,obj_wall)
{
while (!place_meeting(x+sign(hsp),y,obj_wall))
{
x = x+sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical Collision
if place_meeting(x,y+vsp,obj_wall)
{
while (!place_meeting(x,y+sign(vsp),obj_wall))
{
y = y+sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//Attack Animation (Grounded)
if state = states.attack && image_xscale = 1 && vsp = 0
{
instance_create(x+18,y,obj_hitbox);
sprite_index = spr_Durga_attack;
image_speed = 0.5;
hsp = 0;
//Collision knockback
with (instance_create(x,y,obj_hitbox))
{
if instance_place(x,y,obj_shield)
{
var shield = (instance_place(x,y,obj_shield)) //<--- Having issue with this chunk of code.
hsp = sign(x-shield.x)*1.5;
}
}
}
else
{
if state =states.attack && image_xscale = -1 && vsp = 0
{
instance_create(x-18,y,obj_hitbox);
sprite_index = spr_Durga_attack;
image_speed = 0.5;
hsp = 0;
//Collision knockback
with (instance_create(x,y,obj_hitbox))
{
if instance_place(x,y,obj_shield)
{
var shield = (instance_place(x,y,obj_shield)) // Same as the forst but for the opposite direction.
hsp = sign(x-shield.x)*1.5;
}
}
}
}
//Attack Animation(Ariel)
if state = states.attack
{
if image_xscale = 1
{
instance_create(x+18,y,obj_hitbox);
sprite_index = spr_Durga_attack;
image_speed = 0.5;
}
else
{
if image_xscale = -1
{
instance_create(x-18,y,obj_hitbox);
sprite_index = spr_Durga_attack;
image_speed = 0.5;
}
}
}
//Return to Walking Script
if (image_index > image_number -1)
{
state = states.walking
image_speed = 0.1;
}