RuneI
Class Rope

source: c:\runehov\RuneI\Classes\Rope.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.ParticleSystem
         |
         +--RuneI.BeamSystem
            |
            +--RuneI.Rope
Direct Known Subclasses:ClimbableChain, ClimbableVine

class Rope
extends RuneI.BeamSystem

//============================================================================= // Rope. //============================================================================= //NOTES FOR SWAYING EFFECT: //To disable swaying, set bDisableSway to true. //If Swaying is enabled, you can adjust the MaxSway and the IdleSway to suit your needs. //Be carefull of setting MaxSway too high, as it will cause the rope to look bent almost...
Variables
 Actor AttachedActor
           position of attached actor
 float CurMultiplier
           position of attached actor
 float ElapsedTime
           position of attached actor
 float IdleSway
           position of attached actor
 vector LocationAttached
           position of attached actor
 float MaxSway
           position of attached actor
 vector RopeBottom
           Bottom of visual rope as defined by Collision Height
 vector RopeClimbBottom
           Bottom of climbable portion of rope (determined by a trace)
 vector RopeClimbTop
           Top of climbable portion of rope (determined by a trace)
 vector RopeTop
           Top of visual rope as defined by Collision Height
 int ValidControlPoint
           position of attached actor
 bool bActorAttached
           Whether there's a pawn hanging on me
 bool bDisableSway
           position of attached actor


Function Summary
 void AttachedToRope(Actor Other)
 
simulated
ComputeClimbingEndpoints(float tracestartz)
     
// This is done everytime it get's touched because designers might put in breakable geometry (polyobjs)
// between the top and bottom, messing with the trace
 
simulated
Debug(Canvas canvas, int mode)
 void DetachFromRope(Actor Other)
 int GetValidPoint()
 
simulated
PostBeginPlay()



Source Code


00001	//=============================================================================
00002	// Rope.
00003	//=============================================================================
00004	//NOTES FOR SWAYING EFFECT:
00005	//To disable swaying, set bDisableSway to true.
00006	//If Swaying is enabled, you can adjust the MaxSway and the IdleSway to suit your needs.
00007	//Be carefull of setting MaxSway too high, as it will cause the rope to look bent almost...
00008	
00009	class Rope extends BeamSystem;
00010	
00011	var private vector RopeTop;		// Top of visual rope as defined by Collision Height
00012	var private vector RopeBottom;	// Bottom of visual rope as defined by Collision Height
00013	var vector RopeClimbTop;		// Top of climbable portion of rope (determined by a trace)
00014	var vector RopeClimbBottom;		// Bottom of climbable portion of rope (determined by a trace)
00015	
00016	var bool bActorAttached;		// Whether there's a pawn hanging on me
00017	var vector LocationAttached;	// position of attached actor
00018	var Actor AttachedActor;
00019	
00020	var float ElapsedTime;
00021	var float CurMultiplier;
00022	var int ValidControlPoint;
00023	
00024	var (Rope) bool bDisableSway;
00025	var (Rope) float MaxSway;
00026	var (Rope) float IdleSway; 
00027	
00028	simulated function PostBeginPlay()
00029	{
00030		Super.PostBeginPlay();
00031	
00032		// Precompute some constants
00033		RopeTop = Location + vect(0,0,1)*CollisionHeight;
00034		RopeBottom = Location - vect(0,0,1)*CollisionHeight;
00035	
00036		//LocationAttached = Location;
00037		OriginOffset = vect(0,0,1)*CollisionHeight;
00038		TargetLocation = RopeBottom;
00039	
00040		ComputeClimbingEndpoints(Location.Z);
00041	
00042		LocationAttached = Location + vect(0,0,-1) * CollisionHeight;
00043	 
00044	  	if(bDisableSway)
00045	 		bEventSystemTick = False;
00046		else
00047		{
00048			bEventSystemTick = True;
00049			CurMultiplier = IdleSway;
00050	 		ValidControlPoint = 0;
00051	 	}
00052	}
00053	
00054	// This is done everytime it get's touched because designers might put in breakable geometry (polyobjs)
00055	// between the top and bottom, messing with the trace
00056	simulated function ComputeClimbingEndpoints(float tracestartz)
00057	{
00058		local vector HitLocation, HitNormal;
00059		local actor A;
00060		local vector TraceStart;
00061	
00062		TraceStart = Location;
00063		TraceStart.Z = tracestartz;
00064	
00065		A = Trace(HitLocation, HitNormal, RopeTop, TraceStart, false, vect(1,1,1)*20);
00066		if (A!=None)
00067			RopeClimbTop = HitLocation;
00068		else
00069			RopeClimbTop = RopeTop;
00070	
00071		A = Trace(HitLocation, HitNormal, RopeBottom, TraceStart, false, vect(1,1,1)*20);
00072		if (A!=None)
00073			RopeClimbBottom = HitLocation;
00074		else
00075			RopeClimbBottom = RopeBottom;
00076	}
00077	
00078	
00079	function AttachedToRope(actor Other)
00080	{
00081		if (!bActorAttached)		// Disallow if someone using rope already
00082		{
00083			bActorAttached = true;
00084			AttachedActor = Other;
00085			LocationAttached = AttachedActor.Location + vect(0,0,1) * AttachedActor.CollisionHeight;
00086			CurMultiplier = MaxSway;
00087		}
00088	}
00089	
00090	function DetachFromRope(actor Other)
00091	{
00092		bActorAttached = false;
00093		LocationAttached = Location + vect(0,0,-1) * CollisionHeight;
00094		AttachedActor = None;
00095		ValidControlPoint = 0;
00096		CurMultiplier = MaxSway;
00097	
00098		//LocationAttached = Location;
00099	}
00100	
00101	function int GetValidPoint()
00102	{
00103		local int i;
00104		
00105	 	for(i = 1; i < NumConPts; i++)
00106	 	{
00107	 		if(ConnectionPoint[i].Z < LocationAttached.Z) 
00108	 			return i;
00109	 	}
00110	 	
00111	 	return NumConPts;
00112	}
00113	
00114	
00115	//=============================================================================
00116	//
00117	// SystemTick 
00118	//
00119	// Update the rope to sway it (if allowed)
00120	//=============================================================================
00121	event SystemTick(float DeltaSeconds)
00122	{
00123		/*
00124		local int i;
00125		local vector Delta;
00126	
00127		// Locations of rope
00128		Delta = Normal(LocationAttached-RopeTop)*(2*CollisionHeight)/(NumConPts-1);
00129	
00130		for(i = 0; i < NumConPts; i++)
00131		{
00132			ConnectionPoint[i] = RopeTop + i * Delta;
00133		}
00134		*/
00135		
00136		local int i;
00137		local vector tempVect;
00138		ElapsedTime += DeltaSeconds;
00139		
00140		if(bActorAttached)
00141		{						
00142			tempVect = AttachedActor.Location + vect(0,0,-1) * AttachedActor.CollisionHeight;
00143			if(tempVect != LocationAttached) 		//Actor has moved....
00144			{
00145				LocationAttached = tempVect;
00146				CurMultiplier = MaxSway;			//Put some power back into the sway...
00147				ValidControlPoint = GetValidPoint();		//Find the point below the actor..
00148			}
00149		}
00150		
00151			for(i = 1; i < NumConPts; i++)
00152			{
00153				if(i > ValidControlPoint)
00154				{
00155					ConnectionOffset[i].X = ConnectionOffset[i-1].X + CurMultiplier * Sin(ElapsedTime * 2 + ((ValidControlPoint - i)/4)) * (ValidControlPoint - i);
00156					ConnectionOffset[i].Y = ConnectionOffset[i-1].Y + CurMultiplier * Cos(ElapsedTime * 2 + ((ValidControlPoint - i/4))) * (ValidControlPoint - i);
00157				}
00158				else
00159				{
00160					ConnectionOffset[i] = vect(0,0,0);
00161				}	
00162			}
00163		
00164		if(CurMultiplier > (IdleSway + 0.003))		//Slowly decrement the sway amount to let the rope's velocity die out..
00165			CurMultiplier -= 0.003;
00166	}
00167	
00168	
00169	simulated function Debug(Canvas canvas, int mode)
00170	{
00171		local vector offset;
00172		local int i;
00173	
00174		Super.Debug(canvas, mode);
00175	
00176		Canvas.DrawText("Rope:");
00177		Canvas.CurY -= 8;
00178		
00179		Canvas.DrawText("Current Multiplier: " @curMultiplier);
00180		Canvas.CurY -= 8;
00181		Canvas.DrawText("ValidControlPoint: " @ValidControlPoint);
00182	 	Canvas.CurY -= 8;
00183	 	Canvas.DrawText("bDisableSway: " @bDisableSway);
00184		Canvas.CurY -= 8; 		
00185	 	Canvas.DrawText("bEventSystemTick: " @bEventSystemTick);
00186	 	Canvas.CurY -= 8;
00187	
00188	
00189		Canvas.DrawLine3D(RopeClimbTop + vect(20, 0, 0), RopeClimbTop + vect(-20, 0, 0), 255, 0, 0);
00190		Canvas.DrawLine3D(RopeClimbTop + vect(0, 20, 0), RopeClimbTop + vect(0, -20, 0), 255, 0, 0);	
00191		Canvas.DrawLine3D(RopeClimbTop + vect(0, 0, 20), RopeClimbTop + vect(0, 0, -20), 255, 0, 0);
00192	
00193		Canvas.DrawLine3D(RopeClimbBottom + vect(20, 0, 0), RopeClimbBottom + vect(-20, 0, 0), 0, 255, 0);
00194		Canvas.DrawLine3D(RopeClimbBottom + vect(0, 20, 0), RopeClimbBottom + vect(0, -20, 0), 0, 255, 0);	
00195		Canvas.DrawLine3D(RopeClimbBottom + vect(0, 0, 20), RopeClimbBottom + vect(0, 0, -20), 0, 255, 0);
00196		
00197		Canvas.DrawLine3D(LocationAttached + vect(15,15,0), LocationAttached + vect(-15,-15,0),0,255,0);
00198		Canvas.DrawLine3D(LocationAttached + vect(15,-15,0), LocationAttached + vect(-15,15,0),0,255,0);
00199	
00200	/*
00201		// Locations of rope
00202		for(i = 0; i < NumConPts; i++)
00203		{
00204			Canvas.DrawLine3D(ConnectionPoint[i] + vect(10, 0, 0), ConnectionPoint[i] + vect(-10, 0, 0), 0, 255, 0);
00205			Canvas.DrawLine3D(ConnectionPoint[i] + vect(0, 10, 0), ConnectionPoint[i] + vect(0, -10, 0), 0, 255, 0);	
00206			Canvas.DrawLine3D(ConnectionPoint[i] + vect(0, 0, 10), ConnectionPoint[i] + vect(0, 0, -10), 0, 255, 0);
00207		}
00208	*/
00209	}
00210	
00211	defaultproperties
00212	{
00213	     MaxSway=0.800000
00214	     IdleSway=0.100000
00215	     ParticleCount=45
00216	     ParticleTexture(0)=Texture'RuneFX.chain1'
00217	     NumConPts=15
00218	     BeamThickness=2.500000
00219	     BeamTextureScale=0.040000
00220	     bUseTargetLocation=True
00221	     bNet=False
00222	     Texture=Texture'Engine.S_Rope'
00223	     CollisionRadius=15.000000
00224	     CollisionHeight=500.000000
00225	     bCollideActors=True
00226	}

End Source Code