Free-to-use hitzone system
This method is far superior to my previous hitbox solution, it's very fast, easy to use and is based on polygonal detection, it does not use additional models and does not require any special setup (except painting a hitzone mask). It even works fine with bone animations.



It's based on a simple c_trace+SCAN_TEXTURE+USE_POLYGON approach. Normally, the problem is that the collision mesh is different from the animated visible mesh of a model and thus you have to use c_updatehull to reload all of its vertices. As this function is pretty slow, you want to avoid unnecessary calls at all cost.
Therefore you register every animated enemy on entity creation and the code will then only update enemies close to the ray from c_trace's start to target. If there are more than, f.i. 3-5, close objects, they will be sorted by their distance to the trace source and only those enemies' collision mesh will be refreshed.
Those entities should have a hitzone mask as a separate skin, where the different channels (I chose red for damage, green for body part identification) provide the desired information:



Concerning the green channel you have to lay down your own rules: You have 256 possible body parts, now you take for example 0 (= black) as an indicator for a non-defined body part, 1 (that means you paint (1,1,1) in the green channel) for the face, 2 for the back of the head, 10 for the right hand, 11 for the left hand and so on.

Download here (updated: 22.10.2011):
http://www.superku.de/hitzones.zip
(source + example)

The code uses 2 skills and overwrites "on_ent_remove". Have a look at "hitzone.c", there are some other configurable things, too.



Example shoot function:
Code:
hitzone_update(camera.x,temp,0); // write 1 instead of 0 when CLIPPED entities should be taken into account, too
c_trace(camera.x,temp,IGNORE_PASSABLE | USE_POLYGON | SCAN_TEXTURE);
if(you)
{
	damage = hitzone_get_damage(you); // now the vector "hitzone_color" contains the mask information at hit point
	your.health -= damage;
}


Example enemy action:
Code:
action enemy()
{
	hitzone_enemy_add(me);
	//my.hitzone_skin = 3; // optional, the skin "hitzone_skin_default" may already be in use by a shader
	while(my.health > 0)
	{
		...
		wait(1);
	}
	hitzone_enemy_remove(me);
}



Have fun!

Last edited by Superku; 11/21/11 20:30.

"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends