Testing Air Resistance Smashing

Discussions about Coding and Scripting
Post Reply
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Testing Air Resistance Smashing

Post by Gustavo6046 »

Hello all from UT99!

Today, I'll present a mutator.

Code: Select all

//=============================================================================
// SmashableActorsMatch.
//=============================================================================
class SmashableActorsMatch expands Mutator;

var	ActorSpeedInfo	ActorSpeeds;

event bool NewActorSpeedInfo(Actor A)
{
	local	ActorSpeedInfo	ASI;

	if ( ActorSpeeds == None )
	{
		ActorSpeeds = Spawn(class'ActorSpeedInfo', Self);
		ActorSpeeds.CActor = A;
	}
	else
		for (ASI = ActorSpeeds; ASI != None; ASI = ASI.NextInfo)
			if ( ASI.NextInfo == None )
			{
				ASI.NextInfo = Spawn(class'ActorSpeedInfo', Self);
				ASI.NextInfo.CActor = A;
				ASI.NextInfo.PreviousInfo = ASI;
				break;
			}
}

function PostBeginPlay()
{
	local	Actor	A;

	foreach AllActors(class'Actor', A)
	{
		if ( A.bMovable && Pawn(A) != None )
		{
			NewActorSPeedInfo(A);
		}
	}
}

function Tick(float delta)
{
	local	ActorSpeedInfo	ASI;

	for ( ASI = ActorSpeeds; ASI != None; ASI = ASI.Nextinfo )
		if ( ASI.ActorSpeeds[1] > 120 && ASI.ActorSpeeds[0] < 25 )
			ASI.CActor.TakeDamage(ASI.ActorSpeeds[1] / sqrt(ASI.ActorSpeeds[0]), Pawn(ASI.CActor), ASI.CActor.Location, vect(0, 0, 320), 'Smash');
}

//=============================================================================
// ActorSpeedInfo.
//=============================================================================
class ActorSpeedInfo expands Info;

var	Actor			CActor;
var	float			ActorSpeeds[2];
var	ActorSpeedInfo	PreviousInfo;
var	ActorSpeedInfo	NextInfo;

function Tick(float delta)
{
	ActorSpeeds[1] = ActorSpeeds[0];
	ActorSPeeds[0] = VSize(CActor.Velocity);
}
As you can see, it smashes pawns that brakes too fast from a high speed, which causes air resistance smash.

The problem is: How will I test a pawn that moves fast and brakes fast? What can I do to reproduce something like that and see if the actors can be damaged?!
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Testing Air Resistance Smashing

Post by Barbie »

Just some remarks, if desired (and all my code is only compiled by brain, so it may contain errors):
1) finding end of chain of a linked list
That's a common problem and I would put this into the Object itself for easier access and re-use:

Code: Select all

class ActorSpeedInfo expands Info;

function ActorSpeedInfo GetLast() {
local ActorSpeedInfo result;
	result = self;
	while (result.Nextinfo != None)
		result = result.Nextinfo;
	return result;
}
2) In your class ActorSpeedInfo you have the variable "CActor" for game actors. What happens if that Actor has been deleted meanwhile and you access this variable?
3) TakeDamage(ASI.ActorSpeeds[1] / sqrt(ASI.ActorSpeeds[0])...
Division by zero possible?
4)
How will I test a pawn that moves fast and brakes fast
Acceleration is the velocity change by time (and deceleration the same with a negated sign). You can calculate it approximately by a = (v2 - v1) / (t2 - t1)
5)
it smashes pawns that brakes too fast from a high speed, which causes air resistance smash.
Does this effect exist in reality? I only know that fluid (or air) friction that raises with the speed of a moving object.
6)
What can I do to reproduce something like that and see if the actors can be damaged?!
Make a map with a CreatureFactory and put the SpawnPoint really high, perhaps increase zone gravity and have Monsters (MaxItems=1) spawned there. (Keep in mind that a Zone has a maximum velocity defined somewhere.) Additionally use a mutator that shows the health of Pawns.

EDIT:

7) Event driven architecture instead of polling
I would remove SmashableActorsMatch.Tick and call a Mutator function if condition meets:

Code: Select all

function ActorSpeedInfo.Tick(float delta)
{
	...
	if (Acceleration > AccelThreshold)
		if ( ! bInProgress)
			if (IsMyMutator(Owner))
			{
				bInProgress = true;
				MyMutator(Owner).DoAction(self); // *DoAction()* has to set *bInProgress=false* as last statement
			}
}
EDIT2:

To make sure that above event won't be called if still in progress, I have added that *bInProgress* flag.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Testing Air Resistance Smashing

Post by Gustavo6046 »

Thanks for the tips miss killer Barbie! I'll surely implement some way of avoiding that division for zero (which I don't know how to do, or to even improve the algorithm). And I won't even mention the rest, since you'll see it when it's done! :D

It seems I need to improve this code and make it work before going to a next step.

Sometimes I just forget to reply, sorry if It took too long :P
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
Post Reply