DanoMagnum.com

>Skeletalanimation 

Last Edit: Oct. 12, 2014, 11:03 p.m.

I've been playing lots of smash bros lately (melee) in preperation for the new wiiu version and decided to play around a bit with the idea of creating a similar engine.

What I've got so far is far from complete but worth sharing I think. It uses 2d skeletal animation for its visualizations and collision detections.

Here is a video of it in action so far, but I don't have a state engine implemented to control what animation plays when yet so there are some strange artifacts.

In the video above the circles represent what would be quivalent to a hitbox and are generated on the fly during the animations. The animations are handled through animation definition files which I modeled, somewhat, after gcode.

Here are the commands. Bones are individual segments, the skeleton is the whole unit, and orbs are the circles used for collision detection.

COMMANDS = {'BRR':BoneRotateRelative,
		    'BRA':BoneRotateAbsolute,
		    'BRACW': BoneRotateAbsoluteCW,
		    'BRACCW': BoneRotateAbsoluteCCW,
		    'STR': SkeletonTranslateRelative,
		    'SSA': SkeletonScaleAbsolute,
            'AO': AddOrb,
            'NOP': NOP
}

Here is an example animation definition for the "idle" animation:

STR 0 2 10

BRR leftthigh -5 15
BRR leftshin 5 15
BRR rightthigh -5 15
BRR rightshin 5 15

BRR rightbicep -5 15
BRR leftbicep 5 15
BRR rightforearm 5 15
BRR leftforearm -5 15

STR 0 -2 15 15

BRR leftthigh 5 15 15
BRR leftshin -5 15 15
BRR rightthigh 5 15 15
BRR rightshin -5 15 15

BRR rightforearm -5 15 15
BRR leftforearm 5 15 15
BRR rightbicep 5 15 15
BRR leftbicep -5 15 15

and here is one for the "punch" animation.

AO rightforearm 10 1 8 0
AO rightforearm 15 1 5 6

BRA leftbicep -49.0 10
BRA leftforearm -85.0 10
BRA rightbicep -87.0 10
BRA rightforearm -6.0 10
BRA leftbicep -84 20 10
BRA leftforearm -85 20 10
BRA rightbicep -70 20 10
BRA rightforearm -117 20 10

As of now, these animations can be created in the test environment by selecting a bone and then using the mouse wheel to rotate it. When a good position is found, the entire skeleton can be exported as a snapshot which can then be edited with transition times and delays.

The skeletons themselves start by defining the root bone and then attaching other bones to that one based on how far down line segment the child bone should be attached. Orbs are created the same way. In the example below, the arms are attached to the spine 20% of the way from the top.

#class Bone(object):
#	def __init__(self, name, length, theta=0, parent=None, percent=1, theta_min = None, theta_max=None, scale=1.0):

def guy2(): # with no bounds on his skeleton
	spine = Bone('spine', 100, 90)
	leftthigh = Bone('leftthigh', 50, 45, spine, 1)
	rightthigh = Bone('rightthigh', 50, -45, spine, 1)
	leftshin = Bone('leftshin', 50, -30, leftthigh, 1)
	rightshin = Bone('rightshin', 50, 30, rightthigh, 1)
	leftbicep = Bone('leftbicep', 50, 45, spine, 0.2)
	rightbicep = Bone('rightbicep', 50, -45, spine, 0.2)
	leftforearm = Bone('leftforearm', 50, -30, leftbicep, 1)
	rightforearm = Bone('rightforearm', 50, 30, rightbicep, 1)
	neck = Bone('neck', 20, -200, spine, 0)

	s = Skeleton(spine, Point(150, 50))

	s.add_orb('leftshin', 8)
	s.add_orb('rightshin', 8)

	return s

I think this would be a fairly flexible solution for a number of different game types that side scroll. You could probably even make qwop with it if you wanted to.

Instructions

The arrow keys move, jump, and crouch. f kicks. s punches. d disables the idle animation and gravity. a resets to the "boxer" pose. Mouse click selects bones and mouse wheel rotates them. Enter/return outputs the current skeleton position.

Downloads:

I'd love to hear about how professional skeletal animation systems work, so let me know if you have any insight on that.