Alternative to HurtRadius(), extra features.

Discussions about Coding and Scripting
Post Reply
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Alternative to HurtRadius(), extra features.

Post by Higor »

I've been wondering on some common issues related to explosions, and decided to rework the explosion code.
I haven't tested it, expecting some feedback first to make proper modifications.

Code: Select all

function XC_HurtRadius( float DamageAmount, float DamageRadius, name DamageName, float Momentum, vector HitLocation, optional actor HitActor , optional float ExtraSeek)
{
	local actor Victims, aTrace;
	local float damageScale, dist;
	local vector dir, HLoc, HNorm;
	
	if( bHurtEntry )
		return;

	//Hitactor takes full damage, it's a forced hit
	if ( HitActor != none )
	{
		HNorm = Normal(HitActor.Location - HitLocation);
		HitActor.TakeDamage( DamageAmount, Instigator, HitActor.Location - HNorm * 0.5 * (HitActor.CollisionHeight + HitActor.CollisionRadius), HNorm * Momentum, DamageName);
		HitActor.bHurtEntry = true;
	}

	bHurtEntry = true;
	foreach VisibleCollidingActors( class 'Actor', Victims, DamageRadius + ExtraSeek, HitLocation )
	{
		if ( !Victims.bHurtEntry )
		{
			DamageScale = 1;
			aTrace = none;
			ForEach TraceActors( class'Actor', aTrace, HLoc, HNorm, Victims.Location,  HitLocation)
			{
				if ( aTrace == Victims )
				{
					damageScale *= 1 - VSize(HLoc - HitLocation) / DamageRadius;
					if ( damageScale > 0 )
						Victims.TakeDamage( damageScale * DamageAmount, Instigator, HLoc, (Momentum * damageScale * HNorm), DamageName);
					break;
				}
				if ( (aTrace == Level) || (Mover(aTrace) != none) )
					break;

				//Apply damage reduction if blocked by actor, adjustable here
				if ( aTrace.bBlockActors )
					DamageScale *= 0.7;
			}
		}
	}
	bHurtEntry = false;
	if ( HitActor != none )
		HitActor.bHurtEntry = false;
}
Differences:
- Direct impact damage for special explosions, usage is optional.
Ensures this actor receives full damage, to use when a colliding actor is placed outside of map geometry.
Would solve some issues with misplaced FortStandards, and other pawns/decorations placed outside of the map.

- ExtraSeek parameter allows seeking for greater distances, this prevents some low radius projectiles from failing to damage big Pawns.
A common issue is trying to damage a titan with the ASMD or Shock Rifle alt, an ExtraSeek value of 30 or 40 will solve it.

- HitLocation and Momentum vectors are precise, contributes to better hit information.
Some other mutators or actors might find the benefits of this.

- Damage and Momentum correctly scaled due to precision.
HurtRadius doesn't deal full damage if you hit a player's feet or head.

- Movers properly block the traces, even on NM_DedicatedServer mode.
Otherwise, you can kill enemies through doors and lifts on servers.

- Adjustable body shielding damage reduction, now hiding behind a decoration or another player will have positive consequences.
I know a couple of gametypes that could find this very useful...


Opinions?
User avatar
Dr.Flay
Godlike
Posts: 3348
Joined: Thu Aug 04, 2011 9:26 pm
Personal rank: Chaos Evangelist
Location: Kernow, UK
Contact:

Re: Alternative to HurtRadius(), extra features.

Post by Dr.Flay »

:thuup:
:tu:
:rock:
A standard way of dealing with out-of-bounds, lost bots would be very cool. very useful with monsters and zombies etc.
To be honest it all sound great :D
You should talk to Shadow, and see if it can be included or factored in to the SDK, as these are root additions that would have great benefits if made the part of the UT99 standard.
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Alternative to HurtRadius(), extra features.

Post by Feralidragon »

Looks and sounds nice, but I don't understand why you should add ExtraSeek as an argument.

I mean, if the purpose of ExtraSeek is just to be able to hit bigger pawns with smaller radius impacts, you can always calculate such value yourself within the function (from HitActor, or if null, you can either zero it or assume a default value if the radius is small enough), since as someone wanting to do a projectile, I just want to define the Radius and HitActor at max, and not make the math myself of that value.
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Alternative to HurtRadius(), extra features.

Post by Higor »

The extra parameters make this sort of a general function, it will be at the coder's judgement and good sense to determine the best combination for his explosions.
Body shielding could be a parameter as well, with a little modification.
Post Reply