How do I make a one shot kill for enemy?

KC_GamesKC_Games Member, PRO Posts: 86

Right now I have my enemies taking damage from arrows every time they collide until Power <=0 and they are killed. I want to add functionality that if the arrow hits a specific part (brain or just a dot for testing) that the enemy is killed immediately.

I thought of spawning a hit area actor on each enemy that would detect collision with the arrow and then kill the zombie, but that won't work because the spawned hit area actor doesn't stay constrained to the walking enemy.

If I could detect the arrow.Y and if it is like top 10% of enemy's height, then he is killed, but I don't know how to do this.

Was wondering if anyone has any ideas to make a one shot kill for an enemy? Thanks.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2014

    You might want to consider using triangles to figure out whether the kill shot has been hit depending on the location of the player/archer and the enemy. Constrain game.playerX to self.position.X and game.playerY to self.position.Y in the archer actor and constrain game.enemyX to self.position.X and game.enemyY to self.position.Y in the enemy actor. This will allow you to have access to those points...

    In the image below, if you solve for the height of the triangle, "b", you can then determine if a kill shot was made (I'm assuming here that the kill shot location is the intersection of lines "b" and "c"). Note that the bottom side of the triangle, "a", is likely determined by calculating the distance from the player to some offset of the enemy's X position (e.g. x-20).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • KC_GamesKC_Games Member, PRO Posts: 86

    Tatiang, thanks for taking the time to respond. I couldn't quite wrap my head around what you were suggesting but I was able to figure it out after reading your post. I ended up creating a variable that was constrained to the arrow.Y and then when the arrow overlapped an enemy, I would check if the arrow.Y was greater than enemy.Y + 10px. So basically if the arrow.Y was overlapped AND higher than the enemy.Y plus a few pixels to denote the top or brain, then the HP went to 0 instantly. Thanks for your help :p

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2014

    Yes, that's pretty much what I figured out, too. I was intrigued by the question so I ended up making a demo (right & left arrow keys to aim, space bar to shoot).

    Edit: and I think your solution was simpler! :)

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2014

    @tatiang said:
    Yes, that's pretty much what I figured out, too. I was intrigued by the question so I ended up making a demo (right & left arrow keys to aim, space bar to shoot).

    Edit: and I think your solution was simpler! :)

    For once in my life, top of the leader board.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I don't know, @Socks, my eight year old scored 33. I think you need more practice!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822

    @tatiang said:
    I don't know, Socks, my eight year old scored 33. I think you need more practice!

    Yeah, but your 8 year old probably didn't have to play with the code to get a score of 56.

  • KC_GamesKC_Games Member, PRO Posts: 86

    I got 39 :p

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Hours of Track & Field led to my crowning achievement at Kill Shot, @Socks...

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Here's a new, improved version. Still rough around the edges, though.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822

    @tatiang said:
    Here's a new, improved version. Still rough around the edges, though.

    New high score, I swear to god I didn't alter the code in any way . . .

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Hot damn, @Socks! I have my work cut out for me...

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.