Game Development Community

Pixel collision detection

by Darren Stuart · in Torque Game Builder · 07/27/2005 (11:12 am) · 12 replies

I am trying to do a couple of things and pixel collision detection for sprites would make my life easier.

The reason collision poly does not work for what I am doing is because I am trying to create a fighting game and want the limbs in each frame to beable to collide.

and before some says write your own you have the source code, I wouldn't know where to start and have min C++ skills :p

I think this would be ideal feature for a 2d engine.

#1
07/27/2005 (11:14 am)
You could mount sub objects to it with collision :) Then you could "animate" them in script for the fighting moves... just an idea though.
#2
07/27/2005 (3:07 pm)
I have looked at that method but there is a feature that I want to put in that will make it a little different to any fighting game. I would tell ya but then I would have to.. well you know how it goes :p
#3
07/27/2005 (7:04 pm)
You should look into an established fighting game engine such as MUGEN to get an idea of how other games get this done. If I recall correctly, MUGEN uses hitboxes that are declared for each fighter on a per frame basis, which seems terribly time consuming. I'm sure with the capabilities of T2D you cuold find a much more elegant solution.
#4
07/27/2005 (9:03 pm)
Quote:I think this would be ideal feature for a 2d engine.

Pixel-perfect or no, what you really need is the ability to specify collision volumes that are animated with the character's animation.

As I understand it, such a feature will be eventually available, but I don't know if it's coming in the near future. Without it, I don't know if I would choose T2D as the base platform for making fighting games when there are others available that might be more appropriate to the task.

Quote:there is a feature that I want to put in that will make it a little different to any fighting game. I would tell ya but then I would have to.. well you know how it goes

Your secrecy is not making it easy for us to suggest practical solutions to your problem, as we lack specific knowledge of the scope of the problem. It may come down to a choice between keeping your secret and finding a fix for your problem.

Quote:If I recall correctly, MUGEN uses hitboxes that are declared for each fighter on a per frame basis, which seems terribly time consuming. I'm sure with the capabilities of T2D you cuold find a much more elegant solution.

A "more elegant" solution? Providing collision volumes for attacks in each frame of the animation (or, perhaps, as animated tracks alongside the sprite animation, so that you can choose to skip frames and create a rougher version) is a pretty elegant solution. You don't have to bind scripts to your animations, and you never have to worry about animations getting desynchronized from something. Plus, it lets you customize the hit region for gameplay needs. If you look back at Street Fighter 2, there were several attacks where the collision volume didn't precisely match the pixel volumes.

An automated, data-driven solution is preferable to any special-cased script-driven one.

Yes, it takes time, but this isn't (nor should it be) a 3D bone-style animation system, so whatever solution you take is going to have to be done on a per-frame basis, or thereabouts.
#5
07/27/2005 (11:50 pm)
Thanks for the feedback guys, the feature I want to implement is a system where players create thier own fighting styles by creating moves.

thinking about my method might not work because I would need multi hit boxes per character.

back to the drawing board.

a 2d bone system would solve it but I don't think one could be written in TS.
#6
07/28/2005 (12:13 pm)
I have been thinking of this at work today and think I might have a bone system that might work.

it will not have an IK system.

I would mount all the bones and get each bone to pivot on only on its parent.

I would create a keyframe system and pose the bones in each frame.

I would calculate the angle between 2 keyframes and then divide the angle between the frames
and increment the angle each frame.

The position of the bone would be control by its parent object.

hope that makes sense.
#7
09/02/2005 (6:47 am)
Its actually a lot easier than that, simple create a hierarchy
of scene objects mounted at the correct pivot points (with correct origin)
and store key frame angles for each pivot.

Then simply lerp between the keyframes angles for the animation time [0..1]

function lerp( %t, %a, %b ) 
{
		return ( %a + ( ( %b - %a ) * %t ) );
}

So for arm you'd have 3 pivots:

Arm (pivot at shoulder)
    Upper
    Lower  (pivot at elbow)
        Forearm
        Hand  (pivot at wrist)

I've thrown together a quick example in flash for ya here

Use arrow left/right keys to rotate figure, up/down to tuck/pike, space when he hits trampoline to dampen bounce.

Easy as pie

~neo
#8
09/02/2005 (7:26 am)
Cool demo, I still have much more to learn to get this working. I think the new mouse object thats coming in the update will help me create the keyframe editor.

I am not sure I understand how the lerp function relates to the a skeleton.
#9
09/02/2005 (7:49 am)
Works like this:

You have an angle from each key frame pose.
You want the animation from start pose to end pose to take say 1 second.
The lerp function works in the interval 0.0 to 1.0.

So you want to express the animation duration in that interval.

As time progresses between start and end time you simply pass in the current
time and it will give you the interpolated angle at that time.

Of course once you hit 1.0 you go on to the next animation or loop, or whatever else
needs to be done at that time.

So lets do it for the Arm as an example:

function updateNode( %time, %anim, %node )
{
    %angA = %anim.startPose.angArm;
    %angB = %anim.endPose.angArm;

    %angT = lerp( %time, %angA, %angB );

    %node.setRotation( %angT );
}

// somewhere where you do your update loop
// map elapsed time (from when animation was started) to [0.0, 1.0] 

%time = ( %curTimeMS - %anim.startPose.startTimeMarkMS ) / %anim.duration;

updateNode( %time, %anim, %armNode );

... etc

I'll do an example in T2D when I get the time which perhaps would make it a bit clearer...

~neo
#10
09/02/2005 (8:15 am)
Aha thanks for that, a T2D example for be very useful.
#11
09/07/2005 (3:01 pm)
@Darren: You asked for it ;p here you go

~neo
#12
09/07/2005 (3:10 pm)
@Neo ta, just waiting for the completed animation system now :p