Post your movement code. Also, if collision with the player gives the player a horizontal speed anywhere between -14 and 14, then there's a high chance the player will move towards the enemy rather than away from it. Is this intentional?
As for the invincibilty frames, you could add a variable which starts as false, becomes true on collision with the enemy, then has a short timer to count down to make it false again.
Create:
Code:
hit = false;
timerMax = 30;
timer = timerMax;
Collision event (I'm assuming that's where your collision code is):
Code:
if (!obj_player.hit)
{
obj_player.hit = true;
obj_player.HP --;
}
Player step event:
Code:
if (hit)
{
if (timer > 0)
{
timer --;
}
else
{
hit = false;
timer = timerMax;
}
}
No it's not intentional, it's supposed to go away from the enemy so it doesn't kill the player as fast, and for a cool effect.
My movement code:
var hinput = keyboard_check(vk_right) - keyboard_check(vk_left)
if hinput != 0
{
hspeed_ += hinput*acceleration_;
hspeed_ = clamp(hspeed_, -max_hspeed_, max_hspeed_);
} else
{
hspeed_ = lerp(hspeed_, 0, .3);
}
My collision codes:
if !place_meeting (x, y+1, obj_solid)
{
vspeed_ = vspeed_ + gravity_;
} else
{
if keyboard_check_pressed(vk_space)
{
vspeed_ = jump_height_
}
}
if place_meeting (x + hspeed_, y, obj_solid)
{
while !place_meeting (x + sign(hspeed_), y, obj_solid)
{
x += sign(hspeed_);
}
hspeed_ = 0
}
x = x + hspeed_
if place_meeting (x, y + vspeed_, obj_solid)
{
while !place_meeting (x, y + sign(vspeed_), obj_solid)
{
y += sign(vspeed_);
}
vspeed_ = 0
}
y = y + vspeed_
I am just going to mention that I put this code:
obj_player.hspeed_ = random_range(-14,14)
obj_player.y += -4
In a with other() statement in the enemy object in a collision to player event.
Also what does --; do? Just curious