Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UnrealShare.UJumpPad


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
// Written by .:..:
// A jump pad with bot support.
// The jumper itself (starting point).
Class UJumpPad extends UJumpPadEnd;

var() sound JumpSound;
var() vector JumpVelocityModifier;
var() float JumpZHeightModifier;
var() const bool bForceFullAccurancy; // Always jump perfectly into the Dest point, but is a little bit more CPU intensive and may variate the velocity a little bit.
var vector BackUp_Velocity,JumpVelocity;
var Pawn PendingTouch;
var UJumpDest MyDest;

replication
{
	// Replace Jump velocity to client to keep them better in sync with server.
	reliable if ( Role==ROLE_Authority )
		JumpVelocity;
}

function PostBeginPlay()
{
	local byte i;
	local Actor St,En;
	local int RF,D;
	local float ZHgh;

	For( i=0; i<16; i++ )
	{
		if ( Paths[i]==-1 )
			Continue;
		describeSpec(Paths[i],St,En,RF,D);
		if ( UJumpDest(En)!=None )
		{
			MyDest = UJumpDest(En);
			if ( !bForceFullAccurancy )
			{
				ZHgh = CalcRequiredZHeight(En.Location.Z,Location.Z,Region.Zone.ZoneGravity.Z)+JumpZHeightModifier;
				JumpVelocity = SuggestFallVelocity(Location,En.Location,6000,ZHgh);
			}
			else JumpVelocity = MyDest.Location;
			Break;
		}
	}
	JumpVelocity+=JumpVelocityModifier;
	BackUp_Velocity = JumpVelocity;
}
function Reset()
{
	JumpVelocity = BackUp_Velocity;
}
simulated function Touch( Actor Other )
{
	if ( !Other.bIsPawn || Pawn(Other).Health<=0 )
		Return;
	PendingTouch = Pawn(Other);
	Enable('Tick');
}
simulated function Tick( float Delta )
{
	local float ZH;

	if ( PendingTouch!=None && !PendingTouch.bDeleteMe )
	{
		if ( PlayerPawn(PendingTouch)==None )
		{
			PendingTouch.PlayInAir(); // Make sure this pawn plays falling animation.
			PendingTouch.Acceleration = vect(0,0,0);
			if ( MyDest!=None )
				PendingTouch.MoveTarget = MyDest.SpecialHandling(PendingTouch);
		}
		// Only set the physics on server OR net owner.
		if ( Level.NetMode!=NM_Client || (PlayerPawn(PendingTouch)!=None && PlayerPawn(PendingTouch).Player!=None) )
		{
			if ( PendingTouch.Physics!=PHYS_Falling )
				PendingTouch.SetPhysics(PHYS_Falling);
		}
		if ( !bForceFullAccurancy )
			PendingTouch.Velocity = JumpVelocity;
		else
		{
			ZH = CalcRequiredZHeight(JumpVelocity.Z,PendingTouch.Location.Z,Region.Zone.ZoneGravity.Z)+JumpZHeightModifier;
			PendingTouch.Velocity = SuggestFallVelocity(PendingTouch.Location,JumpVelocity,6000,ZH)+JumpVelocityModifier;
		}
		if ( JumpSound!=None && Level.NetMode!=NM_Client )
			MakeJumpNoise();
		PendingTouch = None;
	}
	Disable('Tick');
}
function MakeJumpNoise()
{
	PlaySound(JumpSound);
}
simulated function float CalcRequiredZHeight( float DestZ, float StartZ, float GravZ )
{
	local int LCount;

	if ( GravZ>=0 )
		GravZ = -100;
	DestZ-=StartZ;
	StartZ = 0;
	while ( DestZ>0 && LCount<8000 ) // Due to the inaccurate Unreal Engine physics code we need to do this.
	{
		StartZ+=GravZ*0.05f;
		DestZ+=StartZ*0.05f;
		LCount++;
	}
	Return Abs(StartZ);
}

// Modified from Epic's SuggestJumpVelocity:
simulated final function vector SuggestFallVelocity( vector Start, vector Dest, float MaxXYSpeed, float ZSpeed )
{
	local float gravZ,currentZ,ticks,Floor,velsize;
	local vector Vel;
	local int LCount;

	gravZ = Region.Zone.ZoneGravity.Z;
	if ( gravZ >= 0 ) // negative gravity - pretend its low gravity
		gravZ = -100.f;
	Floor = Dest.Z - Location.Z;

	Vel.Z = ZSpeed;
	while ( (currentZ>floor || Vel.Z>0) && LCount<8000 )
	{
		Vel.Z = Vel.Z + gravZ * 0.05f;
		ticks += 0.05f;
		currentZ = currentZ + Vel.Z * 0.05f;
		LCount++;
	}
	if (Abs(Vel.Z) > 1.f)
		ticks-=(currentZ - floor)/vel.Z; //correct overshoot
	vel = Dest - Start;
	vel.Z = 0.f;
	if (ticks > 0.f)
	{
		velsize = VSize(Vel);
		if ( velsize > 0.f )
			Vel = Vel/velsize;
		Vel*=FMin(MaxXYSpeed, velsize/ticks);
	}
	else Vel = Normal(Vel)*MaxXYSpeed;
	Vel.Z = ZSpeed;
	Return Vel;
}

// Use original behaviour.
function bool CanBindWith( NavigationPoint Start )
{
	return true;
}

function PathBuildingType EdPathBuildExec( NavigationPoint End, out int ForcedDistance )
{
	return Super(LiftExit).EdPathBuildExec(End,ForcedDistance);
}

// Draw trajectory.
function DrawEditorSelection( Canvas C )
{
	local color Color;
	local vector V,P,G;
	local byte i;
	local UJumpDest Dest;

	foreach AllActors(Class'UJumpDest',Dest)
		if( Dest.LiftTag==LiftTag )
			break;
	if( Dest==None )
		return;

	Color = MakeColor(255,255,0);
	V = SuggestFallVelocity(Location,Dest.Location,6000
		,CalcRequiredZHeight(Dest.Location.Z,Location.Z,Region.Zone.ZoneGravity.Z)
		+JumpZHeightModifier)+JumpVelocityModifier;

	G = Region.Zone.ZoneGravity*Square(0.05f);
	V*=0.05f;
	P = Location;
	for( i=0; i<200; ++i )
	{
		V+=G;
		C.Draw3DLine(Color,P,P+V);
		if( !FastTrace(P+V,P) )
			break;
		P+=V;
	}
}

defaultproperties
{
				bStatic=False
				bNoDelete=True
				bEditorSelectRender=True
				RemoteRole=ROLE_SimulatedProxy
				bAlwaysRelevant=True
				bCarriedItem=True
				bCollideActors=True
				NetPriority=7.000000
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: zo 11-11-2012 21:10:28.000 - Creation time: zo 11-11-2012 21:14:21.272 - Created with UnCodeX