# SpatialFear.SFFixedCamera

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 |
    //=============================================================================
    // Spatial Fear
    // Class: SFFixedCamera
    // Description:	Extends StationaryPawn and changes the view to a 3rd person view from the
    // camera position.
    //	Has to be used with a trigger. In a trigger operation the cameras track target
    //	is set to the eventInstigator of the trigger action. In an untrigger operation the view
    //	is switched back to 1st person.
    //	If enabled, the camera will follow it's targets position with the specified "RotationRate" speed.
    //
    //  See below for class properties.
    //
    //  Interesing base class setting: 	RotationRate, defaults to (Pitch=6000,Yaw=6000,Roll=6000)
    //  This is a rotator, that determines the tracking speed used during every tracking intervall(see
    //  below for tracking interval). So using higher values will result in faster tracking movement.
    //  Combined with a lower tracking interval rate a smoot motion should be producable.
    //
    // Author: Markus Nuebel
    //=============================================================================
    class SFFixedCamera extends StationaryPawn;

    var Actor Target; // Private. Stores a reference to our target once we have one.
    var (FixedCamera) bool bTrackTarget; // Enables/Disables tracking of the pawn during the 3rd person view. Default: true.
    var (FixedCamera) class <Pawn>clsTrackedObject; // Class of objects to track. Default: Engine.PlayerPawn
    //var (FixedCamera) float fTrackingInterval; //Tracking interval.  Default is 0.5 (half a second). Smaller values will result in a smoother tracking.

    // Called when triggered
    event Trigger(Actor Other, Pawn eventInstigator)
    {
    	//class'SFUtils'.Static.sfLogEx(15,"SFFixedCamera::Trigger: Other[0] " $ Other.Touching[0].name $ "Other[1] " $ Other.Touching[1].name $ "Other[2] " $ Other.Touching[2].name $ "Other[3] " $ Other.Touching[3].name);

    	if(None != eventInstigator)
    	{
    		if( ClassIsChildOf(eventInstigator.class, clsTrackedObject) )
    //		if( eventInstigator.IsA('PlayerPawn') )
    		{
    			Super.Trigger(Other, eventInstigator);

    			// Set target to track
    			Target = eventInstigator;

    			// Change the view
    			changeView(eventInstigator);

    			// Activate tracking
    			if(bTrackTarget)
    				startTracking();
    		}
    	}

    	// Call to base class
    	Super.Trigger(Other, eventInstigator);
    }

    // Called when untriggered
    event UnTrigger(Actor Other, Pawn eventInstigator)
    {
    	if(None != Target)
    		// Switch back view
    		PlayerPawn(Target).ViewTarget = NONE;

    	// Call to base class
    	Super.UnTrigger(Other, eventInstigator);
    }

    // Changes the view by setting the camera location.
    // If the instigator is a player pawn the camera is set
    // on this instigaor, otherwise it is searched for
    // the first PlayerPawn to find.
    function changeView(Pawn eventInstigator)
    {
    	local	PlayerPawn		A;

    	if(eventInstigator.IsA('PlayerPawn'))
    			PlayerPawn(eventInstigator).ViewTarget = self;
    	else
    	{
    		// Find the first PlayerPawn
    		foreach	AllActors ( class'PlayerPawn', A,)
    		{
    			if(none != A)
    				A.ViewTarget = self;
    		}
    	}
    }

    // Enables the tracking of the camera
    function startTracking()
    {
    	local rotator rotStartDir;

    	// Set initial rotation
        rotStartDir = rotator(Target.Location - Location);
        rotStartDir.Roll = Rotation.Roll;
    	SetRotation(rotStartDir);
    	DesiredRotation = rotStartDir;

    	// Start tracking
    	GotoState('Tracking');
    }

    // The Tracking state checks to make sure our Target is still valid
    // and then uses DesiredRotation to keep in the camera facing them.
    // By setting DesiredRotation and RotationRate you can have the
    // engine automatically rotate to a new direction.
    state Tracking
    {
    	function Tick( float DeltaTime )
    	{
    		if (PlayerPawn(Target).ViewTarget == NONE)
    		{
    		  GotoState('Idle');
    		  return;
    		}

    		DesiredRotation = rotator(Target.Location - Location);
    		DesiredRotation.Roll = Rotation.Roll;
    	}

      function Timer()
      {
      }

    Begin:
      // SetTimer(fTrackingInterval, true); // Currently disabled, we are using constant tracking
      SetPhysics(PHYS_Rotating);
    }

    // The idle state has nothing to do
    auto state Idle
    {
    }

    //	fTrackingInterval=0.1

    defaultproperties
    {
         bTrackTarget=True
         clsTrackedObject=Class'Engine.PlayerPawn'
         bHidden=True
         bIsPawn=False
         DrawType=DT_Sprite
         bCollideActors=False
         bCollideWorld=False
         bBlockActors=False
         bBlockPlayers=False
         bProjTarget=False
         RotationRate=(Pitch=6000,Yaw=6000,Roll=6000)
    }

class file time: 12/7/2003 3:58:24 PM - creation time: 12/7/2003 4:03:44 PM
Created with UnCodeX