I am trying to implement a zoom from OverShoulderCam to A FPS style cam instead of third person to shoulder. I do also have a third person camera class so really I would just need the correct code for implementing the zoom can some one point me in the right direction please. I want the zoom so it is almost like the player is looking down the gun through the sights, common in most fps games.
My Code is :
Pawn Class:
PlayerController Class:
Camera Class
My Code is :
Pawn Class:
Code:
class RhonePawn extends UTPawn HideCategories(Movement, AI, Camera, Debug, Attachment, Physics, Advanced, Object); //makes player temporarily invulnerable to the enemy attacks so life depletes slower var bool bInvulnerable; var float InvulnerableTime; var bool bScoreDeaths; //sprint speed and stamina variables var float SprintSpeed; var float WalkSpeed; var float Stamina; var float SprintTimer; var float SprintRecoverTimer; var float Empty; var bool bSprinting; /** Used to decrease the poison length each tick */ var int PoisonCountdown; /** Stores our flashlight */ var RhoneWeaponFlashlight Flashlight; /** Used for flashing damage as pawn's HP drops */ var float DamageOverlayTime; var LinearColor DamageBodyMatColor; ///*************************************************************************** //* Tells the pawn to draw all postrender functions //* http://forums.epicgames.com/archive/index.php/t-901388.html //***************************************************************************/ //simulated function PostRenderFor(PlayerController PC, Canvas Canvas, vector CameraPosition, //vector CameraDir) //{ //local vector ScreenPos; // //Super.PostRenderFor(PC, Canvas, CameraPosition, CameraDir); // //ScreenPos = Canvas.Project(self.Location); ////canvas.setPos(200,200); //canvas.SetPos(ScreenPos.X,ScreenPos.Y +100); //canvas.DrawText("TEST POST RENDER!"); //canvas.TextSize(Canvas.TextSize); // //} /*************************************************************************** * Lets us know that the class is being called, for debugging purposes ***************************************************************************/ simulated event PostBeginPlay() { Super.PostBeginPlay(); `Log("================"); `Log("Rhone Pawn up"); /** Flashlight */ Flashlight = Spawn(class'RhoneWeaponFlashlight', self); // Spawns the light on the player, setting self as owner Flashlight.SetBase(self); // Sets the lights base on at the player Flashlight.LightComponent.SetEnabled(false); // Light is off by default Flashlight.LightComponent.SetLightProperties(0.75); // Starts at 75% brightness FlashDmg(); /** called from UTPawn, spawns the default controller */ SpawnDefaultController(); } /*************************************************************************** * Called by RhoneWeapon_PoisonDamage when the pawn is shot ***************************************************************************/ function PoisonPlayer() { PoisonCountdown = 0; // Reset Poison Counter SetTimer(0.5, true, 'PoisonDmg'); // Every .5 seconds PoisonDmg() will be called } /*************************************************************************** * NES style flashing damage timer to indicate how hurt a pawn is ***************************************************************************/ function FlashDmgTimer() { if (Health < HealthMax /2) { `log("HP is less than 50%"); SetTimer(2.2, true, 'FlashDmg'); } if (Health < HealthMax /4) { `log("HP is less than 25%"); SetTimer(1.5, true, 'FlashDmg'); } if (Health < HealthMax /10) { `log("HP is less than 10%"); SetTimer(0.7, true, 'FlashDmg'); } } /*************************************************************************** * Sets the flashing overlay on the pawn to indicate damage taken ***************************************************************************/ simulated function FlashDmg() { SetBodyMatColor(DamageBodyMatColor, DamageOverlayTime); } /*************************************************************************** * Called when a pawn is hit ***************************************************************************/ function PlayHit(float Damage, Controller InstigatedBy, vector HitLocation, class<DamageType> damageType, vector Momentum, TraceHitInfo HitInfo) { Super.PlayHit(Damage, InstigatedBy, HitLocation, DamageType, Momentum, HitInfo); FlashDmgTimer(); } /*************************************************************************** * Actually does the damage to the pawn ***************************************************************************/ function PoisonDmg() { Local Pawn P; P = self; // Set the pawn to yourself /** Does 5 damage to the pawn of type UTDmgType_Burning */ TakeDamage( 5, None, Location, vect(0,0,0) , class'UTDmgType_Burning'); PoisonCountdown=PoisonCountdown+1; // Increment timer `Log("***Pawn Health:" @P.Health); // Log for debugging /** clear the infinitely looping 0.5 second timer after 10 counts of damage */ if(PoisonCountdown >= 10) { ClearTimer('PoisonDmg'); } } /*************************************************************************** * Turns the light on and off ***************************************************************************/ exec function ToggleFlashlight() { if(!Flashlight.LightComponent.bEnabled) // If the light is off... { Flashlight.LightComponent.SetEnabled(true); // Then turn it on `log("TOGGLE FLASHLIGHT ON"); } else // If it's already on { Flashlight.LightComponent.SetEnabled(false);// Turn it off `log("TOGGLE FLASHLIGHT OFF"); } } /*************************************************************************** * Forces the flashlight to use our pawn's rotation ***************************************************************************/ event UpdateEyeHeight( float DeltaTime ) { Super.UpdateEyeHeight(DeltaTime); Flashlight.SetRotation(Controller.Rotation); // Flashlight will use our controller's rotation /** Offset the light slightly, so that it looks as though it is coming from our pawn's eyes/helmet */ Flashlight.SetRelativeLocation(Controller.RelativeLocation + vect(20, 0, 25)); } ///*********************************************************************************** //**USED FOR TOP DOWN Camera** //* Forces the weapon to use the pawn's direction for aiming, and not the camera's //* shots will be fired in the direction the gun is pointed. Used by PlayerController //* Comment this out if you are not using any camera system other than top down. //* @return POVRot. //***********************************************************************************/ //simulated singular event Rotator GetBaseAimRotation() //{ //local rotator POVRot, tempRot; // //tempRot = Rotation; //SetRotation(tempRot); //POVRot = Rotation; // //// Stops the player from being able to adjust the pitch of the shot, forcing the camera to always point //// down towards the pawn. We can still rotate left and right, however. //// POVRot.Pitch = 0; // //return POVRot; //} /*************************************************************************** * Returns base Aim Rotation without any adjustment. We simply use our rotation * Only use this if you want your weapon trace to follow where your gun is * pointed. Projectiles will now follow your trace. Comment out if you want * to fire in middle of screen. * @return POVRot ***************************************************************************/ simulated singular event Rotator GetBaseAimRotation() { local rotator POVRot; // We simply use our rotation POVRot = Rotation; // If our Pitch is 0, then use RemoveViewPitch if( POVRot.Pitch == 0 ) { POVRot.Pitch = RemoteViewPitch << 8; } return POVRot; } event Bump(Actor Other, PrimitiveComponent OtherComp, vector HitNormal) { if(RhoneEnemy(Other) != none && !bInvulnerable) { bInvulnerable = true; SetTimer(InvulnerableTime, false, 'EndInvulnerable'); TakeDamage(RhoneEnemy(Other).BumpDamage, none, Location, vect(0,0,0), class'UTDmgType_LinkPlasma'); } } function EndInvulnerable() { bInvulnerable = false; } exec function startSprint() { GroundSpeed = SprintSpeed; bSprinting = true; if(GroundSpeed == SprintSpeed) { StopFiring(); SetTimer(SprintTimer, false, 'EmptySprint'); } } exec function stopSprint() { GroundSpeed = WalkSpeed; } simulated function EmptySprint() { Stamina = Empty; GroundSpeed = WalkSpeed; bSprinting = true; SetTimer(SprintRecoverTimer, false, 'ReplenishStamina'); } simulated function ReplenishStamina() { Stamina = 20.0; bSprinting = false; } simulated function PlayFootStepSound(int FootDown) { super.PlayFootStepSound(FootDown); } defaultproperties { /** AI and navigation */ bAvoidLedges=true // don't get too close to ledges bStopAtLedges=true // if bAvoidLedges and bStopAtLedges, Pawn doesn't try to walk along the edge at all bUpdateEyeHeight=true // Updates eye height so that the flashlight can become dynamic /** Used for flashing damage as pawn's HP drops */ DamageOverlayTime=.1 // The flash lasts this long (float) DamageBodyMatColor=(R=10) // Sets the pawn to flash red (hence the R=10) /** PostRender functions */ bPostRenderIfNotVisible = true // IF true, may call PostRenderFor() even when this actor is not visible bPostRenderOtherTeam=true // If true, call postrenderfor() even if on different team //invulnerable bScoreDeaths=false bCanPickupInventory=True InvulnerableTime=0.6 //sprint and stamina settings GroundSpeed=200.0 AirSpeed=200.0 WalkSpeed=220.0 SprintSpeed=500.0 SprintTimer=12.0 SprintRecoverTimer=8.0 Stamina=10.0 Empty=1 }
Code:
class RhonePlayerController extends PlayerController; // Reference to the camera properties var const RhoneCameraProperties CameraProperties; /** Array used for setting the number of spawned companions */ var Pawn Companions[3]; var Actor CurrentPickup; /************************************************************************************ * Rotator where the pawn will be aiming the weapon, forces the game to use the pawn's * direction for aiming, not camera's ************************************************************************************/ function Rotator GetAdjustedAimFor(Weapon W, vector StartFireLoc) { return Pawn.GetBaseAimRotation(); } /************************************************************************************ * Spawns companion pawns ************************************************************************************/ function PlayerSpawned(NavigationPoint StartLocation) { Companions[0] = Spawn(Class'RhonePawn',,, StartLocation.Location - vect(75,100,0), StartLocation.Rotation); Companions[1] = Spawn(Class'RhonePawn',,, StartLocation.Location - vect(150,120,0), StartLocation.Rotation); Companions[2] = Spawn(Class'RhonePawn',,, StartLocation.Location - vect(200,280,0), StartLocation.Rotation); } /* ================================================ ValidPickup() Checks whether or not a certain actor is actually something we can pickup or not. Rather bad way to go about it, but since PickupFactories, DroppedPickups etc don't share and common parent class, aside from Actor, I'm unsure what to check for yet... ================================================ */ function bool ValidPickup(Actor Pickup) { // all dropped pickups can be picked up, else they wouldn't exist if (DroppedPickup(Pickup) != None) { return true; } else if (PickupFactory(Pickup) != None) { // If a pickup factory is hidden, it can't be picked up return (PickupFactory(Pickup).bPickupHidden == false); } // If a pickup factory is hidden, it can't be picked up else if (UTCarriedObject(Pickup) != None) { if (UTCarriedObject(Pickup).bHome == true) { return true; } if (UTCarriedObject(Pickup).IsInState('Dropped')) { return true; } } // not a valid pickup return false; } /* ================================================ FindPickup() Finds a pickup (dropped, factory, weapon cache etc) within a limited radius. Returns true if its valid. ================================================ */ function bool FindPickup() { local Actor Pickup, Best; local vector ViewDir, PawnLoc2D, PickupLoc2D; local float NewDot, BestDot; if (Pawn == None) { return false; } CurrentPickup = None; // are we standing on one? if ((Pawn.Base != None) && ValidPickup(Pawn.Base)) { CurrentPickup = Pawn.Base; return true; } // Pick best nearby item PawnLoc2D = Pawn.Location; PawnLoc2D.Z = 0; ViewDir = vector(Pawn.Rotation); ForEach Pawn.OverlappingActors(class'Actor', Pickup, Pawn.VehicleCheckRadius) { if (ValidPickup(Pickup)) { // Prefer items that Pawn is facing PickupLoc2D = Pickup.Location; PickupLoc2D.Z = 0; NewDot = Normal(PickupLoc2D-PawnLoc2D) Dot ViewDir; if ((Best == None) || (NewDot > BestDot)) { // check that item is visible if ( FastTrace(Pickup.Location,Pawn.Location) ) { Best = Pickup; BestDot = NewDot; } } } } // remember what we found please CurrentPickup = Best; // if Best is not NULL, we found something return (Best != None); } simulated function bool PerformedUseAction() { Super.PerformedUseAction(); // If we find a valid pickup, touch it. if (FindPickup()) { CurrentPickup.Touch(Pawn, None, CurrentPickup.Location, Normal(CurrentPickup.Location-Pawn.Location)); pawn.bCanPickupInventory = true; return true; } } /************************************************************************************************************* * Place the name of the camera you want to use in here. If you want to adjust it on the fly within the editor, * use the Archetype that we've created, so Class'RhoneGameCamera'. * Otherwise, enter the name of the class you'd like to use. i.e. 'ThirdPersonCam' *************************************************************************************************************/ defaultproperties { //Switch between the different styles of camera // Allows us to use the camera archetype within the editor to change values on the fly //CameraClass = Class'ThirdPersonCam'//Telling the player controller to use your custom camera script CameraClass = Class'OverShoulderCam'//Telling the player controller to use your custom camera script //CameraClass = Class'FirstPersonCam'//Telling the player controller to use your custom camera script //CameraClass = Class'TopDownCam'//Telling the player controller to use your custom camera script //CameraClass = Class'SideScrollingCam'//Telling the player controller to use your custom camera script CheatClass=class'DebugMenu' // Reference for DebugMenu }
Code:
class OverShoulderCam extends Camera; //Hardcoded vector offset we will use, rather than tweaking values in the editor's CameraProperties var const Vector OSCamOffset; //Hardcoded rotator offset we will use, rather than tweaking values in the editor's CameraProperties var const Rotator OSCamOffsetRotation; /********************************************************************************** * Query ViewTarget and outputs Point Of View. * * @param OutVT ViewTarget to use. * @param DeltaTime Delta Time since last camera update (in seconds) **********************************************************************************/ function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime) { local Pawn Pawn; local Vector V, PotentialCameraLocation, HitLocation, HitNormal; local Actor HitActor; // UpdateViewTarget for the camera class we're extending from Super.UpdateViewTarget(OutVT, DeltaTime); // If there is an interpolation, don't update outgoing viewtarget if (PendingViewTarget.Target != None && OutVT == ViewTarget && BlendParams.bLockOutgoing) { return; } Pawn = Pawn(OutVT.Target); if (Pawn != None) { // Hide the pawn's first-person weapon if(Pawn.Weapon != none) { Pawn.Weapon.SetHidden(true); } /************************************************************************************************ * If you know the name of the bone socket you want to use, then replace 'WeaponPoint' with yours. * Otherwise, just use the Pawn's eye view point as your starting point *************************************************************************************************/ //socket not found, use the other way of updating vectors if (Pawn.Mesh.GetSocketWorldLocationAndRotation('WeaponPoint', OutVT.POV.Location, OutVT.POV.Rotation) == false) { //Start the camera location from the target eye view point OutVT.Target.GetActorEyesViewPoint(OutVT.POV.Location, OutVT.POV.Rotation); } // Force the camera to use the target's rotation OutVT.Target.GetActorEyesViewPoint(V, OutVT.POV.Rotation); // Add the camera offset OutVT.POV.Rotation += OSCamOffsetRotation; // Math for the potential camera location PotentialCameraLocation = OutVT.POV.Location + (OSCamOffset >> OutVT.POV.Rotation); // Draw a trace to see if the potential camera location will work HitActor = Trace(HitLocation, HitNormal, PotentialCameraLocation, OutVT.POV.Location, true,,, TRACEFLAG_BULLET); // Will the trace hit world geometry? If so then use the hit location and offset it by the hit normal if (HitActor != None && HitActor.bWorldGeometry) { OutVT.POV.Location = HitLocation + HitNormal * 16.f; } else { OutVT.POV.Location = PotentialCameraLocation; } } } // Hardcoded vector & rotator values for our camera defaultproperties { OSCamOffset=(x=-60,y=20,z=25) OSCamOffsetRotation=(Pitch=-2048) } /******************** *****Reference******* ********************* * 65536 = 360 degrees * 32768 = 180 degrees * 16384 = 90 degrees * 8192 = 45 degrees * 182 = 1 degree *********************/
Comment