Game Development Community

Opinions wanted: How to check for a successful punch in a 2D action/fight game similar to Double Dragon/Final Fight etc

by Brian · in Torque X 2D · 01/20/2009 (3:41 pm) · 10 replies

So, I'm working on my game, I've already got it half working as in, I can move around, punch (animated), have an AI triggered to chase you around, but I need to do a check to see if there are any "enemy" characters around when attacking. I was thinking about using Scenegraph.FindObjects() but I was worried this would be costly if every character on the screen did this for every attack. Another thing I was thinking might be a possibility would be to have an invisible punch collision zone and put it on the character but I'm not sure if that will return a list of possible guys to punch so I can get the closest from it. Anyhow, I'm open to suggestions.

#1
01/20/2009 (7:51 pm)
Personally I created a invisible collide object at the position of the fist. Then you can just write your code to do whatever when the collider object collides with the enemy.
#2
01/20/2009 (8:01 pm)
@Matthew
That sounds good, but the reason looking into alternate routes is because I'm looking to have it so that if the player is surrounded, if the enemy that is behind you is closer, the character will actually elbow them instead. Basically taking the burden off the player to have to keep turning around. :) I'll do some research though and if it turns out that it is too resource intensive I will definitely try out your solution. Thanks for the suggestion!

Brian

P.S. I'm also thinking about a hybrid approach where I use a wide collision box that checks to see if anyone is even around the character which will skip the scenegraph checks unless the collision box is reporting collisions.
#3
01/20/2009 (8:15 pm)
It's hard to offer meaningful advice without much more details - like are the punches simple contact, or can you land punches to specific areas of the enemy. Also, what's the size of the player? How many of them on screen at once? How accurate does the punch need to be? etc...

Overall, I advise against searching the whole scenegraph on every tick, that's just a waste of CPU. I would do this with a collision component that raises an event when a collision is detected. If detailed hits are important, like a boxing game, you can mount multiple blank scene objects to the player (for head/body/groin(ouch)/etc.), each with their own collision triggers.

You won't be able to mount a scene object with a collision component in a way that moves with your player animation - that is - the mounted object is normally stationary onced added to the scene oblect. So, you'll need to write code that moves the collision object along with the attack command.

Anyway, just a few thoughts to get you started.

John K.
www.envygames.com
#4
01/20/2009 (8:57 pm)
@John

Thanks for the ideas.

The game is one of those games that wikipedia classifies as Beat_'em_up using the 3/4ths view that allows faking depth of moment (up and down). A more modern game that is a lot like what I'm going for would be Castle Crashers without the RPG elements. There are no specific damage points on the Character (player or ai driven). The only complexity is that the ai currently tries to surround players which means generally more than one valid target will be available for attacks. I'm trying to get it so the player will automatically target the closest enemy that may not necessarily be in front of him for an attack Example: AI is behind Player, but there is also one in front. Both AI are in range. Since AI behind is closer, player automatically elbows him instead of attacking the character in front of him.

The lucky part is, right now, the way I'm working with my Character/Player, it only checks input/ai on ticks as well as run through the main Player code on a tick. There are functions in the Player component to get requests from either my AI component or my Input component.

Basically, as it is currently implemented, whenever your character performs some task, it is flagged as busy until the animation is complete (except for walking which can be interrupted by any other task but plays it's animation on a continuous loop until told to stop). So technically, the FindObject function would only be running as fast as the animation could complete.

My current idea is to also, have a wider collision zone the size of the farthest attack you can do (excluding projectile style attacks) and only run that check if there is at least one thing in the collision zone.

A quick question I should ask is this, is there a way to do an on demand collision check that isn't continuous? Also, do you think I'm going about this all wrong? Sorry, I'm still trying to learn. :) Any feedback is appreciated!

Brian
#5
01/20/2009 (10:34 pm)
Take a collection of animated sprites that represent your players movement animations. This animated sprite object has a collision rectangle that extends slightly outside (and in front of) the player's facing direction. (you can optionally mount a larger blank scene object with the necessary collision bounds) The enemies have an object type, like typeEnemy. When the user presses a specific attack/punch button on the keyboard/controller, then you perform the T2DScenegraph.FindObjects with a small range distance from the player's position.

Any object of typeEnemy within that FindObjects rectangle counts has being hit - Show a hit particle effect at the position of the struck enemy. Set a physics force with an X/Y value that the player is facing them (for the knock back). Switch their animation to a fall/death animation. Drop their rendering opacity to fade out. And then schedule a callback after a few milliseconds to MarkForDelete and wipe them out. This way one good swing can send 4 or 5 guys flying at once - true to Brawler style. Just remember to add some random variance to the physics force, so that the enemies fly back at various arcs - that should look pretty good.

You will still need to go the collision delegate route to accomodate the enemies attacking the player. When the typeEnemy crosses the player bounding box, that should trigger the attack against the player and bring down the player's health level.

Just remember to shift the collision bounding box if you horizontally flip the player character. Oh, and start small! Prototype - get one player to knock out one enemy that is standing still before you dive into the full level design and details. I would also be interested in seeing scren captures. Lastly, this might be of interest to you if you are sourcing you player/scene artwork from 3D models. I'm just about ready to take on some public beta testing.

John K.
www.envygames.com
#6
01/20/2009 (11:00 pm)
Awesome! I will definitely do that. The project itself isn't too ambitious. I chose a brawler to start with to learn the engine since it doesn't have to be too in depth like an RPG or such... that and to get a game done for morale. I'll release more information when I feel I have something to really show. This is more to cut my teeth on Torque X than anything else. Anyway, thanks for the help! Oh, I have been following that tool, that is a really awesome utility. If I do make the jump to 3D models, I'd definitely be interested.

Brian
#7
02/12/2009 (5:09 am)
Actually, that appears to be exactly what we're looking for as well. However, I'm at an impass on how the FindObjects function works (such as parameters, usage, etc). It doesn't appear in my doucmentation, and though I have Torque version 1.6, I don't know if that command is is applicable. If anyone could point us to the proper thread or doc. file we'd appreciate it.

Thanks,
Jarid
#8
02/12/2009 (9:22 am)
Hey Jarid,
This particular function is for Torque X. Are you looking for an equivalent for TGE? Here's the information on it for Torque X. Keep in mind this link is talking about Torque X 3.0 which is not out yet so you would need to follow the information posted earlier to do it in Torque X 2.0.

Brian
#9
02/17/2009 (7:26 pm)
Sorry about the late reply. I read your response and rushed to get a kluge together using a trigger that appears and disappears with the animation. Unfortunately, we're only working in Torque Game Builder (Two Dimensions), so this tool proably won't be available to us. Thanks for your help.
#10
02/17/2009 (11:18 pm)
I'm not too familiar with TGB other than the editor for TXB2D being based off TGB. I wish I could help you there. I would double check in the TGB forum as I'm sure someone there would know. It's possible because a lot of the concepts for TX2D have origins there.

Torque Game Builder Forum
Torque Game Builder Official Documentation

Brian