Enemy killing Help please

N

NizarPlayz

Guest
Hi once again. So my problem is that i have a health bar of my player and if the player touches enemy it health gets low and also my player can jump so how can i do that if i jump on the top of the enemy head the enemy gets killed and if it touches from the side my player health gets low so how can i make it Just like Super mario,Red ball
 
Last edited by a moderator:
Enemy Step Event:
Code:
if(place_meeting(x,y-1,obj_player))  {
instance_destroy() //or what you want to happen when the player hits the enemy's head
}
Player Step Event:
Code:
if(place_meeting(x+1,y,obj_enemy) || place_meeting(x-1,y,obj_enemy)) {
health -= 0.1 //or what you want to happen when the enemy is touching him
}
if(health <= 0) {
instance_destroy()
}
this should work, I couldn't test it right this second so if it doesn't let me know and I'll fix it :)
 
Last edited:
N

NizarPlayz

Guest
Enemy Step Event:
Code:
if(place_meeting(x,y-1,obj_player))  {
instance_destroy() //or what you want to happen when the player hits the enemy's head
}
Player Step Event:
Code:
if(place_meeting(x+1,y,obj_enemy) || place_meeting(x-1,y,obj_enemy)) {
health -= 0.1 //or what you want to happen when the enemy is touching him
if(health <= 0) {
instance_destroy()
}
}
this should work, I couldn't test it right this second so if it doesn't let me know and I'll fix it :)
Hey um i already have a step event in my player so what can i do now? which other event i should use
 
Hey um i already have a step event in my player so what can i do now? which other event i should use
what code is already in it, you might have to remove some of it. But to add that code, if you didn't already know :) , just drag and drop a code event into the step event
 
N

NizarPlayz

Guest
in the step event i have this code
if place_free(x,y+1) then{gravity=0.5}
else{gravity=0}

if vspeed>12 then{vspeed=12}
this is for the player jumping and i tried that enemy code when my player touched him he got disappear if you don't understand let me explain full problem
So actually the enemy is moving left and right so i want it to be if my player touches enemy from left or right it health gets low and if my player jumps on enemy head the enemy gets killed do you understand now?
 
Last edited by a moderator:
in the step event i have this code
if place_free(x,y+1) then{gravity=0.5}
else{gravity=0}

if vspeed>12 then{vspeed=12}
this is for the player jumping and i tried that enemy code when my player touched him he got disappear if don't understand let me explain full problem
So actually the enemy is moving left and right so i want it to be if my player touches enemy from left or right it health gets low and if my player jumps on enemy head the enemy gets killed do you understand now?
okay give me a sec I'm going to test it :)
 
ok so these codes will work:
Player Step:
Code:
if(instance_exists(objEnemy)) {
if(place_meeting(x+1,y,objEnemy) || place_meeting(x-1,y,objEnemy)) {
h -= 10 //or what you want to happen when the enemy is touching him
}
if(h <= 0) {
instance_destroy()
}
}
Enemy Step:
Code:
if(instance_exists(objPlayer)) {
if(place_meeting(x,y-1,objPlayer))  {
h -= 30
if(h <= 0) {
instance_destroy()
}
}
}
You need to have some way for the player to sorta bounce away from the enemy after he touches you or you are just going to either keep hurting the enemy or yourself.
Also, you need to change objPlayer to the name of your player and objEnemy to the name of your enemy objects and h to your health variable
 
N

NizarPlayz

Guest
ok so these codes will work:
Player Step:
Code:
if(instance_exists(objEnemy)) {
if(place_meeting(x+1,y,objEnemy) || place_meeting(x-1,y,objEnemy)) {
h -= 10 //or what you want to happen when the enemy is touching him
}
if(h <= 0) {
instance_destroy()
}
}
Enemy Step:
Code:
if(instance_exists(objPlayer)) {
if(place_meeting(x,y-1,objPlayer))  {
h -= 30
if(h <= 0) {
instance_destroy()
}
}
}
You need to have some way for the player to sorta bounce away from the enemy after he touches you or you are just going to either keep hurting the enemy or yourself.
Also, you need to change objPlayer to the name of your player and objEnemy to the name of your enemy objects and h to your health variable
But what about my code that i have for the player jumping in the event Step?
 
N

NizarPlayz

Guest
they should work together, if you don't your player to fall inside of your enemy then make sure that the enemy is also solid
if i make my enemy solid and my player touches it it just get stuck on it + i managed to execute the code on begin step event now i'll try yours
 
Top