Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by esschul

Hi, I have an entity that I'm jumping on with another entity, and would like to detect whether I hit the head or the body.

In the check-method:


var iHaveHitTheEntitysHead = ?
If (iHaveHitTheEntitysHead ){
spawnCoin
add damage to this.entity
} else {
// I have hit the rest of the body.
add damage to this entity
add damage to the other entity
}

Does anyone have any idea how to do this?

1 decade ago by Joncom

You could create a separate entity that represents the head and then on each draw call make sure you sync the head position to its body.

1 decade ago by lTyl

You can override the check method in your enemy entity and then compare your players Y value to the enemy Y value. If you want to check if you land on TOP of the enemy, then it will look something like this:

if (player.y < this.pos.y){
// Player Y is less than entity Y, but a collision happened. Therefore player is ABOVE enemy
} else {
// Player Y is not less than entity Y, but a collision happened. Therefore player is NOT above enemy
}

this.parent( other );

1 decade ago by esschul

That last answer from ITyl worked like a charm (and was the easiest).

1 decade ago by esschul

That last answer from ITyl worked like a charm (and was the easiest).
Page 1 of 1
« first « previous next › last »