UE2:KarmaThing

From Unreal Wiki, The Unreal Engine Documentation Site

KarmaThing

Coded by unknown author. We got the script from a mapper who said that the creator allowed to freely distribute this script, so I put it in my tool set to make it easy available for everyone. Originally published in the package 'KarmaOnline'.


UT2004 Object >> Actor >> KActor >> KarmaThing (custom)
Known custom subclass:
Crusha/UltimateMappingTools/UltimateDestructibleEnvironment

Usually KActors don't work properly in netplay. Their collision is replicated by the server, but they don't change their visual location on the clients. This is a fixed version of the KActor that works in online games.

Variables

Except for one variable there is nothing new to the level designer in compare to a KActor. Here you can learn how to set up a KActor properly to achieve what you want.


Property group 'KarmaThing'

MaxNetUpdateInterval

Type: float

How frequently the location and rotation of the KActor gets updated for the client. The lower this value the more frequent gets it updated.

Default value: 0.5


Script Code

This is the original code, if someone is interested.

<uscript> //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- class KarmaThing extends KActor

   placeable;

var() float MaxNetUpdateInterval; var float NextNetUpdateTime;

var KRigidBodyState KState, KRepState; var bool bNewKState; var int StateCount, LastStateCount;

replication {

   unreliable if(Role == ROLE_Authority)
       KRepState, StateCount;

}

function Tick(float Delta) {

   PackState();

}

//Pack current state to be replicated function PackState() {

   local bool bChanged;
   if(!KIsAwake())
       return;
   KGetRigidBodyState(KState);
   bChanged = Level.TimeSeconds > NextNetUpdateTime;
   bChanged = bChanged || VSize(KRBVecToVector(KState.Position) - KRBVecToVector(KRepState.Position)) > 5;
   bChanged = bChanged || VSize(KRBVecToVector(KState.LinVel) - KRBVecToVector(KRepState.LinVel)) > 1;
   bChanged = bChanged || VSize(KRBVecToVector(KState.AngVel) - KRBVecToVector(KRepState.AngVel)) > 1;
   if(bChanged)
   {
       NextNetUpdateTime = Level.TimeSeconds + MaxNetUpdateInterval;
       KRepState = KState;
       StateCount++;
   }
   else
       return;

}

//New state recieved. simulated event PostNetReceive() {

   if(StateCount == LastStateCount)
       return;

}

//Apply new state. simulated event bool KUpdateState(out KRigidBodyState newState) {

   //This should never get called on the server - but just in case!
   if(Role == ROLE_Authority || StateCount == LastStateCount)
       return false;
   //Apply received data as new position of actor.
   newState = KRepState;
   StateCount = LastStateCount;
   return true;

}

DefaultProperties {

   MaxNetUpdateInterval=0.5

} </uscript>