RuneI
Class SpringPoint

source: c:\runehov\RuneI\Classes\SpringPoint.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--RuneI.Accelerator
         |
         +--RuneI.SpringPoint
Direct Known Subclasses:None

class SpringPoint
extends RuneI.Accelerator

//============================================================================= // SpringPoint. //=============================================================================
Variables
 float DampFactor
           Dampening factor [0..1] (0 = no dampening)
 float MaxVelocityPickup
           Maximum velocity transfer allowed from collision
 vector OriginalPos
           Maximum velocity transfer allowed from collision
 float SpringConstant
           Spring Tension constant [0..] (0 = no tension)

States
Active, Inactive

Function Summary
 void Bump(Actor Other)
 void PreBeginPlay()
 void SpringPointTick(float DeltaSeconds)
 void Touch(Actor Other)
 void WakeUp()


State Active Function Summary
 void BeginState()
 void Tick(float DeltaTime)


State Inactive Function Summary
 void BeginState()



Source Code


00001	//=============================================================================
00002	// SpringPoint.
00003	//=============================================================================
00004	class SpringPoint extends Accelerator
00005		intrinsic;
00006	
00007	
00008	var() float SpringConstant;			// Spring Tension constant [0..] (0 = no tension)
00009	var() float DampFactor;				// Dampening factor [0..1] (0 = no dampening)
00010	var() float MaxVelocityPickup;		// Maximum velocity transfer allowed from collision
00011	
00012	var vector OriginalPos;
00013	
00014	intrinsic(653) final function SpringPointTick(float DeltaSeconds);
00015	
00016	function PreBeginPlay()
00017	{
00018		OriginalPos = Location;
00019		DampFactor = FClamp(DampFactor, -1.0, 1.0);
00020	}
00021	
00022	function Touch(actor Other)
00023	{
00024		Velocity += Normal(Other.Velocity) * Min(VSize(Other.Velocity), MaxVelocityPickup);
00025		WakeUp();
00026	}
00027	
00028	function Bump(actor Other)
00029	{
00030		if (Other.IsA('Pawn'))
00031		{
00032			Velocity += Normal(Other.Velocity) * Min(VSize(Other.Velocity), MaxVelocityPickup);
00033			WakeUp();
00034		}
00035	}
00036	
00037	function WakeUp()
00038	{
00039		GotoState('Active');
00040	}
00041	
00042	state Inactive
00043	{
00044		ignores Tick;
00045	
00046		function BeginState()
00047		{
00048			SetPhysics(PHYS_NONE);
00049		}
00050	}
00051	
00052	
00053	auto state Active
00054	{
00055		function Tick(float DeltaTime)
00056		{
00057			SpringPointTick(DeltaTime);
00058	/*
00059			local vector deviation;
00060			
00061			// Apply spring acceleration based on deviation from original position
00062			deviation = OriginalPos - Location;
00063			Velocity += deviation * (SpringConstant * DeltaTime / Mass);
00064			Velocity *= (1.0 - DampFactor);
00065	*/
00066	
00067			if (VSize(Velocity) < 0.1)
00068			{
00069				Velocity = vect(0,0,0);
00070				GotoState('Inactive');
00071			}
00072		}
00073	
00074		function BeginState()
00075		{
00076			SetPhysics(PHYS_PROJECTILE);
00077		}
00078	}
00079	
00080	defaultproperties
00081	{
00082	     SpringConstant=2000.000000
00083	     DampFactor=0.100000
00084	     MaxVelocityPickup=500.000000
00085	     Physics=PHYS_Projectile
00086	     CollisionRadius=30.000000
00087	     CollisionHeight=30.000000
00088	     bCollideActors=True
00089	     bCollideWorld=True
00090	}

End Source Code