how do you subtract point from player only if it get hit

emojiemoji Member, BASIC Posts: 66

hello again everyone. how do I subtract point from the player if only the enemy punch or kick the player and not walk by and touch the player. I hope this question make sense

Comments

  • ArmellineArmelline Member, PRO Posts: 5,397

    Do the subtracting in the enemies. If the enemy is punching the player AND overlaps with the player (or whatever condition is needed) then subtract a point.

  • emojiemoji Member, BASIC Posts: 66

    i though of the same idea was wondering if there are any other way but appreciated the response. I will work on it and if i have any question i will let you know.

  • ArmellineArmelline Member, PRO Posts: 5,397

    What is it you're trying to do that makes you want a different way? There are other ways of handling it but what I described will normally be the best way. If you can provide some more details we can see if there's a better way for your use case.

  • emojiemoji Member, BASIC Posts: 66

    oh i didn't really mean it in a mean way. i have a player in a beat them up game and i have a box that the player follow (the box is a hit point) and whenever the enemy hit that box the player point would be subtract. i guess i can check if the enemy is colliding and punching the box is true. I appreciated the response. I haven't implemented yet. It not easy like it sound.

  • emojiemoji Member, BASIC Posts: 66

    i have this but everytime my player punch the enemy, the enemy life would subtract more than one

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    You should use a Change Attribute instead of a Constrain Attribute.

    Change Attribute game.enemy.score to game.enemy.score - 1

  • emojiemoji Member, BASIC Posts: 66

    oh thank you very much it works

  • bob loblawbob loblaw Member, PRO Posts: 793
    edited April 2020

    and if it's a combat game, consider using hit boxes for your collisions, that way you can make the collisions based on where proper contact is, rather than each time two entire sprites come into contact (see attached demo). left/right keys to move. space to strike.


Sign In or Register to comment.