Back to Scripting…

After a bit of time marking, moderating and other work related duties, I’ve decided to revisit RoyChr’s tutorial for creating a Isometric Camera.

What I have achieved today is a combination for his tutorial and a 3rd person camera script created by syntaxerror22.

With RoyChr’s tutorial, it has mouse based movement which is something that I didn’t want. I did get up to the end of Chapter 1 but previously I lost the actual mesh for the pawn. After reading that the source download had been updated, I implemented his newer code and found my guy had returned. Not being overly happy with the angle I adjusted the pitch to -45 degrees and the Yaw to 45 degrees. I moved the camera out to (-1536,-1536,2048) and changed the FOV to 17 degrees. In testing I am using a 360 controller and this currently has no modification in any way.

So the following has been set up with May 2011 Beta. All credit for the scripts go to syntaxerror22 and Christian Roy

SourceĀ RetroShooter

DefaultEngine.ini

[UnrealEd.EditorEngine]
+EditPackages=UTGame
+EditPackages=UTGameContent
+ModEditPackages=RetroShooter

DefaultGame.ini

[Engine.GameInfo]
DefaultGame=RetroShooter.RetroShooterGameInfo
DefaultServerGame=RetroShooter.RetroShooterGameInfo
;DefaultGame=UTGame.UTDeathmatch
;DefaultServerGame=UTGame.UTDeathmatch
PlayerControllerClassName=UTGame.UTPlayerController

RetroShooterGameInfo.uc

class RetroShooterGameInfo extends GameInfo;

DefaultProperties
{
  bDelayedStart=false
  PlayerControllerClass=class'RetroShooter.RetroShooterPlayerController'
  DefaultPawnClass=class'RetroShooter.MyPawn'

}

RetroShooterPlayerController.uc
class RetroShooterPlayerController extends GamePlayerController;

state PlayerWalking
{
ignores SeePlayer, HearNoise, Bump;

   function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
   {
    local Vector tempAccel;
    local Rotator CameraRotationYawOnly;

      if( Pawn == None )
      {
         return;
      }

      if (Role == ROLE_Authority)
      {
         // Update ViewPitch for remote clients
         Pawn.SetRemoteViewPitch( Rotation.Pitch );
      }

      tempAccel.Y =  PlayerInput.aStrafe * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
      tempAccel.X = PlayerInput.aForward * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
      tempAccel.Z = 0; //no vertical movement for now, may be needed by ladders later

   //get the controller yaw to transform our movement-accelerations by
  CameraRotationYawOnly.Yaw = Rotation.Yaw;
  tempAccel = tempAccel>>CameraRotationYawOnly; //transform the input by the camera World orientation so that it's in World frame
  Pawn.Acceleration = tempAccel;

  Pawn.FaceRotation(Rotation,DeltaTime); //notify pawn of rotation

    CheckJumpOrDuck();
   }
}

//Controller rotates with turning input
function UpdateRotation( float DeltaTime )
{
local Rotator   DeltaRot, newRotation, ViewRotation;

   ViewRotation = Rotation;
   if (Pawn!=none)
   {
      Pawn.SetDesiredRotation(ViewRotation);
   }

   // Calculate Delta to be applied on ViewRotation
   DeltaRot.Yaw   = PlayerInput.aTurn;
   DeltaRot.Pitch   = PlayerInput.aLookUp;

   ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
   SetRotation(ViewRotation);

   NewRotation = ViewRotation;
   NewRotation.Roll = Rotation.Roll;

   if ( Pawn != None )
      Pawn.FaceRotation(NewRotation, deltatime); //notify pawn of rotation
}   

DefaultProperties
{
  CameraClass=class'RetroShooter.RetroIsoCamera';
}

simulated event PostBeginPlay()
{
super.PostBeginPlay();
`Log("I am alive");
}

MyPawn.uc
class MyPawn extends GamePawn;

simulated event PostBeginPlay()
{
  super.PostBeginPlay();
  `Log("Custom Pawn up");
}

simulated function name GetDefaultCameraMode( PlayerController RequestedBy )
{
  `Log("Requested Isometric");
    return 'Isometric';
}

simulated function FaceRotation(rotator NewRotation, float DeltaTime)
{
  // Do not update Pawn's rotation if no accel
  if (Normal(Acceleration)!=vect(0,0,0))
  {
    if ( Physics == PHYS_Ladder )
    {
      NewRotation = OnLadder.Walldir;
    }
    else if ( (Physics == PHYS_Walking) || (Physics == PHYS_Falling) )
    {
      NewRotation = rotator((Location + Normal(Acceleration))-Location);
      NewRotation.Pitch = 0;
    }

    SetRotation(NewRotation);
  }

}

defaultproperties
{
  Components.Remove(Sprite)

  Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
    ModShadowFadeoutTime=0.25
    MinTimeBetweenFullUpdates=0.2
    AmbientGlow=(R=.01,G=.01,B=.01,A=1)
    AmbientShadowColor=(R=0.15,G=0.15,B=0.15)
    LightShadowMode=LightShadow_ModulateBetter
    ShadowFilterQuality=SFQ_High
    bSynthesizeSHLight=TRUE
  End Object
  Components.Add(MyLightEnvironment)

    Begin Object Class=SkeletalMeshComponent Name=InitialSkeletalMesh
    CastShadow=true
    bCastDynamicShadow=true
    bOwnerNoSee=false
    LightEnvironment=MyLightEnvironment;
        BlockRigidBody=true;
        CollideActors=true;
        BlockZeroExtent=true;
    PhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
    AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_AimOffset'
    AnimSets(1)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    SkeletalMesh=SkeletalMesh'CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode'
  End Object

  Mesh=InitialSkeletalMesh;
  Components.Add(InitialSkeletalMesh);
}

RetroIsoCamera.uc
class RetroIsoCamera extends Camera;

function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
{
  local vector            Loc, Pos, HitLocation, HitNormal;
  local rotator           Rot;
  local Actor                     HitActor;
  local CameraActor       CamActor;
  local bool                      bDoNotApplyModifiers;
  local TPOV                      OrigPOV;

  // store previous POV, in case we need it later
  OrigPOV = OutVT.POV;

  // Default FOV on viewtarget
  OutVT.POV.FOV = DefaultFOV;

  // Viewing through a camera actor.
  CamActor = CameraActor(OutVT.Target);
  if( CamActor != None )
  {
    CamActor.GetCameraView(DeltaTime, OutVT.POV);

    // Grab aspect ratio from the CameraActor.
    bConstrainAspectRatio   = bConstrainAspectRatio || CamActor.bConstrainAspectRatio;
    OutVT.AspectRatio               = CamActor.AspectRatio;

    // See if the CameraActor wants to override the PostProcess settings used.
    CamOverridePostProcessAlpha = CamActor.CamOverridePostProcessAlpha;
    CamPostProcessSettings = CamActor.CamOverridePostProcess;
  }
  else
  {
  // Give Pawn Viewtarget a chance to dictate the camera position.
  // If Pawn doesn't override the camera view, then we proceed with our own defaults
    if( Pawn(OutVT.Target) == None ||
      !Pawn(OutVT.Target).CalcCamera(DeltaTime, OutVT.POV.Location, OutVT.POV.Rotation, OutVT.POV.FOV) )
    {
  // don't apply modifiers when using these debug camera modes.
      bDoNotApplyModifiers = TRUE;

    switch( CameraStyle )
    {
      case 'Fixed'            :       // do not update, keep previous camera position by restoring
        // saved POV, in case CalcCamera changes it but still returns false
        OutVT.POV = OrigPOV;
        break;

      case 'ThirdPerson'      : // Simple third person view implementation
      case 'FreeCam'          :
      case 'FreeCam_Default':
        Loc = OutVT.Target.Location;
        Rot = OutVT.Target.Rotation;

        //OutVT.Target.GetActorEyesViewPoint(Loc, Rot);
        if( CameraStyle == 'FreeCam' || CameraStyle == 'FreeCam_Default' )
        {
          Rot = PCOwner.Rotation;
        }
        Loc += FreeCamOffset >> Rot;

        Pos = Loc - Vector(Rot) * FreeCamDistance;
        // @fixme, respect BlockingVolume.bBlockCamera=false
        HitActor = Trace(HitLocation, HitNormal, Pos, Loc, FALSE, vect(12,12,12));
        OutVT.POV.Location = (HitActor == None) ? Pos : HitLocation;
        OutVT.POV.Rotation = Rot;
        break;

      case 'Isometric':
        // fix Camera rotation
        Rot.Pitch = (-45.0f     *DegToRad) * RadToUnrRot;
        Rot.Roll =  (0          *DegToRad) * RadToUnrRot;
        Rot.Yaw =   (45.0f      *DegToRad) * RadToUnrRot;

        Loc.X = PCOwner.Pawn.Location.X - 1536;
        Loc.Y = PCOwner.Pawn.Location.Y - 1536;
        Loc.Z = PCOwner.Pawn.Location.Z + 2048;

        Pos = Loc - Vector(Rot) * FreeCamDistance;

        OutVT.POV.Location = Pos;
        OutVT.POV.Rotation = Rot;
        break;

      case 'FirstPerson'      : // Simple first person, view through viewtarget's 'eyes'
        default                         :       OutVT.Target.GetActorEyesViewPoint(OutVT.POV.Location, OutVT.POV.Rotation);
        break;

      }
    }
  }

  if( !bDoNotApplyModifiers )
  {
  // Apply camera modifiers at the end (view shakes for example)
    ApplyCameraModifiers(DeltaTime, OutVT.POV);
  }
//`log( WorldInfo.TimeSeconds  @ GetFuncName() @ OutVT.Target @ OutVT.POV.Location @ OutVT.POV.Rotation @ OutVT.POV.FOV );
}

DefaultProperties
{
  DefaultFOV=17.f
}

This entry was posted in UDK. Bookmark the permalink.