A face sensitive object

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

A face sensitive object

Post by Sir Robin »

I've got some objects (actors) in my mod that the player can use or bump into. I've got them represented by models instead of billboard sprites, so makes sense that the player should only be able to use them from the front of the model since that's where the switches and interactive parts are drawn on the models. There's nothing built-in to let an object only be triggered from a certain way so I wrote my own. This could be useful if you want a similar feature.

It works by checking the front plane of the hitbox against rays intersecting it. The front plane is projected according to the actor's angle, and is not axis-aligned ike the actual hitbox, so this routine is 360-degrees accurate. A limitation is that I don't consider z, Since Doom's "use" doesnt consider z, I didn't bother with it either.

Could also use this for example if you have a wheeled cart and the player can move it, but only from the front or back. Or create one of those annoying puzzles where they have to move blocks out of their way but the blocks only move in certain directions.

This could also be useful for example if you want to create a monster that can only be hit from the front, or negate that and it can only be hit from not the front. Or offset the detection angle and make a monster that is only hittable from the back. Or one that takes double damage from the back. You could also use this to detect if a projectile is a glancing blow instead of a direct hit and make glancing hits bounce off. But that last one you could probably do that with simpler math that I've got here.

Anyway, here's the code:
Spoiler:
To help see how the code is working I'd suggest attaching a perfect cube model to the actor, the same size as the hitbox, or just use the radius debugger to do that automatically
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: A face sensitive object

Post by Sir Robin »

creating a monster that can only take damage from the front was way easier:

Code: Select all

	override int TakeSpecialDamage (Actor inflictor, Actor source, int damage, Name damagetype)
	{
		if (!inflictor || (inflictor && absangle(angleto(inflictor),angle) <= 45)
			return super.TakeSpecialDamage(inflictor, source, damage, damagetype);
		return 0;
	}
Since the inflictor already gives me an intersection point, I don't have to bother calculating it with a ray.

It still bleeds no matter which direction you hit it from, and I'm not sure how to fix that yet.

Return to “Script Library”