-2

i developed a scene in levelHelper software. But now i am stuck in the part that how to check that player/hero sprite is hit with the enemy which part like is it hit from up,down,left,right. I want to do this b/c i want the player to die when it hit from left,right,down. But if it hit from the upside the enemy should destroy like in super mario game. so how can i do this till now i am checking that if the y position of the player is greater than enemy than it mean it hit from the upside. But i am facing problem in my scenario in which enemy sprite is little smaller than player so it's y position is always less than player and also it's width so what formula or method i use to make this thing happen thanks in advance.

2 Answers2

0

Have you checked the documentation? http://www.gamedevhelper.com/documentation/documentation.html > LHContactInfo Class

Basically you should create fixtures within SpriteHelper and you can check the collision like the example code provided..

NSString* fixNameA = [contact fixtureNameA];
NSString* fixNameB = [contact fixtureNameB];

if(fixNameA != NULL && 
([fixNameA isEqualToString:@"LegRight"] || [fixNameA isEqualToString:@"LegLeft"]))
{
//apply 30% damage
}

if(fixNameA != NULL && 
([fixNameA isEqualToString:@"RightArm"] || [fixNameA isEqualToString:@"LeftArm"]))
{
//apply 50% damage
}

if(fixNameA != NULL && [fixNameA isEqualToString:@"Head"])
{
//apply 100% damage
}
user1526474
  • 925
  • 13
  • 26
0
if ( player.position.y > enemy.position.y && fabs( player.position.x - enemy.position.x ) < enemy.size.width / 2 ) {

This will ensure that not only is the player above the enemy, but the player is at the same horizontal space. basically, it will only trigger if you are hitting the enemy from above, and not from the sides or below.

dqhendricks
  • 19,030
  • 11
  • 50
  • 83