GameMaker I always take damage even when I jump on top of the enemies

GONE

Member
Hello everyone,

I am making a platformer and wanted the main way to kill enemies is by jumping on top of them. I added this code to my game and discovered that no matter where I jump on them I take damage. here are my codes

Oplayer

// attacking

if(instance_exists(Oenemy)) {
if(place_meeting(x+1,y,Oenemy) || place_meeting(x-1,y,Oenemy)) {
hp -= 1
}
if(hp <= 0) {
instance_destroy()
}
}


Oenemy

// damage taken
if(instance_exists(Oplayer)) {
if(place_meeting(x,y-1,Oplayer)) || place_meeting(x,y+1,Oplayer) {
hp -= 4

}
}

I think what I need to do is make my character automatically bounce off them. If you know how to do that please tell. also, try not to make complex codes, I recently started coding.
 

Amon

Member
Do the damage check for your player only when he is grounded or has just started jumping. Have damage occure only to the enemy when your character is falling. So, you need to track how high your character can jump and when at the apex of the jump, set a bool to true that tracks when your character is falling. Put the damage code for the enemy in that.

if ( falling )
{
if ( place_meeting(,x, y+1, Oenemy )
{
////kill enemy or damage enemy
///set falling to false
}
}
 
Top