Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Sprite Collision for fighting game

Author
Message
Riz
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location:
Posted: 7th Apr 2009 00:40
Hey guys i could use some help i got my sprite collision working for my fighting game when a sprite is hit the health bar goes down. My problem is that when player 1 hits player 2 not only does player 2's health go down but player 1's health goes down as well and vice versa. I was wondering how exactly would i remedy this so that when player 1 hits player 2 only player 2's health goes and when player 2 hits player 1 only player 1's health goes down id apreciate any help you guys can provide thanks.
Databug
15
Years of Service
User Offline
Joined: 27th Oct 2008
Location: Elsewhere
Posted: 8th Apr 2009 06:05
What i would do is to set a "state" of a player attacking,
i.e. if player 1 attacks, attackstate1 = 1 or something. Then if that state is active, the player doesn't take damage. That then leads to when both players attack at the same time, they cancel
out each others attacks, creating a sort of blocking effect. Then u can create different states like state 2 beats a state 1(like a crushing attack vs a normal one or defense) and so on. But im getting off topic...

Or u can make seperate sprites for the fists/swords/whatever

hope it helps

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Apr 2009 14:38
One problem I see already is that you have only the frame number to go on, if player 1 is attacking, and player 2 touches them anywhere, then it would count as a hit.

I think you need hot spots; on each sprite frame you'd have a separate reference for telling your engine where the hit is intended to land. So if you used an array, and stored the X and Y position of each hot spot for each frame, then you would check each hot spot for the other players collision.

You haven't said though, what sort of collision you are using for the characters right now, as I know you have to be using some sort of pixel perfect collision system.

One option is to have the hit areas as separate frames - so for every frame you might have a hot spot version, maybe with just the hand that is punching, the leg that is kicking, different areas would be viable hot spots in an attack animation. I think this is the easiest option for a pre-built per pixel sprite collision, as you'd simply swap out the sprites used in the collision check, and you will have total control over everything. If you use .PNG images for the sprites, then the hot spot versions would be really small as well, don't be concerned about memory usage.


Health, Ammo, and bacon and eggs!
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 8th Apr 2009 21:12 Edited at: 8th Apr 2009 21:23
short on time after preparing this but i think a combination of both suggestions above would work well. it's a simple distance check between 2 "hot spots" as van b suggest using "states" flags per databug. it's NOT pixel perfect but could be considered accurate enough for your basic sprite-based fighter game.

some commented pseudo-code:


and a zoomed-in, less-than-perfect visual to go with it:
note, fighter1 is on the left, fist hotspot outlined and the sprite x,y reference point marked in red. green = fighter2.


the concept is there but you would definitely be fleshing this out more to include fist/feet vs head, torso, legs, etc, checks as well. perhaps using different shape checks. ie, represent torso and legs with rectangles (hotboxes) instead of circles (hotspots).

hope this helps! after whipping up the old-school karate champ-styled sprite samples, i now wanna make a full game

Attachments

Login to view attachments
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Apr 2009 23:22
Hehe, nice sprites - I always wanted to remake IK+


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2024-04-13 03:44:06
Your offset time is: 2024-04-13 03:44:06