RedWarriorKTF
Member
Hi all! I've spent 2 days trying to get this to work and I know I'm close but being a noob is not easy. I had a look at all the other forums but it doesn't seem to be what I need or is a different method.
So in my 2d platformer when player is hit by an enemy I want them to get knocked left or right depending on the side of the enemy I get hit from.
Here is my code so far. I assume I need the "Sign" function in there but im not sure how to utilise it.
if (place_meeting(x,y,oHamish))
{
if (oHamish.y < y-16)
{
with (oHamish) vsp = jump;
}
else
{
if (oHamish.x > x-16)
{
with (oHamish) hsp = -10;
}
}
}
As you can see if I collide from the top I jump, if I collide from the left I get knocked back. How do I get the right side to knock me back? I have tried using sign but I am obviously writing it wrong if that's what I should do.
Anyway, Thanks to any one who can help. Love you all. You have all been so helpful.
So in my 2d platformer when player is hit by an enemy I want them to get knocked left or right depending on the side of the enemy I get hit from.
Here is my code so far. I assume I need the "Sign" function in there but im not sure how to utilise it.
if (place_meeting(x,y,oHamish))
{
if (oHamish.y < y-16)
{
with (oHamish) vsp = jump;
}
else
{
if (oHamish.x > x-16)
{
with (oHamish) hsp = -10;
}
}
}
As you can see if I collide from the top I jump, if I collide from the left I get knocked back. How do I get the right side to knock me back? I have tried using sign but I am obviously writing it wrong if that's what I should do.
Anyway, Thanks to any one who can help. Love you all. You have all been so helpful.
Last edited: