Hitzone system

Posted By: Superku

Hitzone system - 10/21/11 23:07

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!
Posted By: Quad

Re: Hitzone system - 10/22/11 10:03

Awesome idea, and awesome execution!
Posted By: Blattsalat

Re: Hitzone system - 10/22/11 10:45

Very nice!
I will have to test this.

Thanks a lot for the contribution.

cheers and have a nice one,
Posted By: Superku

Re: Hitzone system - 10/22/11 13:17

You're welcome!
I've uploaded a small "fix", the old "hitzone.c" said that you have to call the function hitzone_init() at game start but you don't, it was an empty prototype.
Posted By: alibaba

Re: Hitzone system - 11/21/11 19:21

Itīs not possible to use it with A8, isnīt it?
Posted By: Superku

Re: Hitzone system - 11/21/11 19:51

Of course it is, I only use A8. What problems do you encounter?
Posted By: alibaba

Re: Hitzone system - 11/21/11 20:08

c_updatehull, the problem is, that i use bone animated models.
Posted By: Superku

Re: Hitzone system - 11/21/11 20:27

There is no problem with bone animation and/ or combination of bone animations (at least with ANM_ADD and ent_animate, did not try anything else), this works fine.
Posted By: alibaba

Re: Hitzone system - 11/21/11 20:55

No Problems in A8, but A7 does not support Hull updates with bone animation.
Posted By: Superku

Re: Hitzone system - 11/21/11 21:12

Quote:
Itīs not possible to use it with A8, isnīt it?

Hm that question is cleared now, correct? If so, have fun and good luck with your project!
Posted By: alibaba

Re: Hitzone system - 11/21/11 21:17

Thank you laugh
Just hoped that there may be another way.
Posted By: Superku

Re: Hitzone system - 11/21/11 21:23

Ah I'm sorry, you are using A7 and were asking for an A7 version. I fear you have to use models/ hitboxes with bone animation in A7.
Posted By: alibaba

Re: Hitzone system - 11/21/11 21:34

Yep, but again thank you! Iīm using yourīs laugh
© 2024 lite-C Forums