Collision Detection Advanced

TouchTiltGamesTouchTiltGames Member Posts: 1,162
edited November -1 in Working with GS (Mac)
I want to record a score for when an object hits an actor (enemy character) in a particular area. So for the head: 50 points, body: 25 points and legs: 10 points for example. Right now I've got it set up so that if the enemy is hit you get X points but I want to break its body up into 3 sections.

Is the best way to do this by using invisible/constrained actors for the body parts if when hit then X points? Or is there an easier way? :)

Comments

  • design219design219 Member Posts: 2,273
    This was something I wanted to do with my first game, which came out about 6 months ago. I've kept my eye out for another solution, but have yet to see one. The constraining multiple actors works pretty well, I've done that in Nesen Probe, but I've heard that too many actors and constraints start to take a major toll on performance.

    Best of luck.

    _______________

    Nesen Probe http://itunes.apple.com/us/app/nesen-probe/id377766693?mt=8
    Tickle Stones http://itunes.apple.com/us/app/tickle-stones/id363484260?mt=8
    Food Fight! (free) http://itunes.apple.com/us/app/food-fight/id352646643?mt=8
  • A3MGA3MG Member Posts: 152
    Can you compare the y position of the enemy and the y position of the weapon (bullet)? Then do some calculations. When the bullet collides with the enemy check to see how high or low compared to the y position of the enemy. If the bullet hits 30 pixels above the center of the enemy position do the rule for the head shot -- if the bullet hits at the same y position calculate a gut shot -- if the bullet hits 30 pixels below do the legs rule.
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Yeah I had wondered about getting the Y coordinates of the enemy based on the pixel height value...It sounds like something that's doable....
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Oh this is great thanks! But if I have 3 of the same enemies on the screen, all 3 'head' detection boxes go to the same enemy and not the other two lol.
  • reddotincreddotinc Member Posts: 653
    You probably need to set up 3 constrains and then update them within each instance of the enemy actor
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    A3MG has the best solution. As long as your enemies aren't spinning around and the "head" is always above the center of the actor, it should be relatively easy.

    Create a game attribute that gets set to the current bullet's Y when ever a collision happens. That logic would be in the bullet actor.

    In the enemy, have it compare the value of game.CurrentBulletY to its own Y position when it senses a collision.

    Lets says your enemy actor's head makes up the top 1/4 of the actor...

    When collides with Bullet AND
    When game.CurrentBulletY is >= self.Y+(self.height/4):
    "Head Shot"
  • design219design219 Member Posts: 2,273
    Shizane said:
    I have 3 of the same enemies on the screen, all 3 'head' detection boxes go to the same enemy and not the other two lol.

    You probably need the three to be different actors, even if they look and behave the same.
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    3 separate head actors...I've got those all on the screen but they're all going to the same enemy.

    You mean 3 separate attributes? So: player1 x player 1 y, player2 x player 2 y, player3 x player3 y....
  • design219design219 Member Posts: 2,273
    Yes, three attributes should do, if you are not spawning enemies, just working with prototypes of one actor.
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Yeah I'm spawning 3 of the same actor so I'm having to create 3 of everything :) Thanks for the help.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    I'm not sure if you're interested, but I created a quick demo using the method A3MG and I were talking about.

    http://gamesalad.com/game/play/68537
  • A3MGA3MG Member Posts: 152
    @barkbark - nice astronaut!

    I have not upgraded to 0.8.8 yet, but the screen came up with the gun and the enemies with the three different shaded areas.

    Thanks for putting this together.
  • A3MGA3MG Member Posts: 152
    Installed 0.8.8 - nice work!
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    @A3MG, Did it pretty much sum up what you were getting at?

    I know it's not really well commented, but I think it's a pretty comprehensible demo regardless...
Sign In or Register to comment.