Friday, October 5, 2012

Cookbook: Sidescroller-like first person view

"I want to make a game like a Sidescroller but in first-person view. So you can only walk forward and backward and jump. No strafe to the left or right."

Based on this question in epicgames forums, I've taken some time to create a simple solution  (not superb, partially hardcoded, but you can continue from that) for anybody interested :).

Here we go:

I'll base all code changes on this cool tutorial for Sidescroller: http://udn.epicgames.com/Three/DevelopmentKitGemsPlatformerStarterKit.html

What we need to do is:
  • Update camera behavior so it is positioned in front of pawn and points in direction of positive Y axis
    • first part can be done in archetyped CameraProperties directly in Editor:
Experiment with StarterPlatformGameContent package (Content browser in editor) and change CameraProperties.CameraOffset vector:
FPS like view (X=0,Y=10,Z=50) -> camera slightly in front of pawn model, only weapon visible
over the arm camera (X=-20,Y=-20,Z=50) -> head, arms and weapon visible
    • second part requires simple code change (SPG_Camera.uc):

   1:  function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
   2:  {
   3:     ...
   4:   
   5:     // Make the camera point towards the target's location
   6:     //REPLACE THIS:
   7:     //OutVT.POV.Rotation = Rotator(OutVT.Target.Location - OutVT.POV.Location);
   8:   
   9:     //WITH THIS:
  10:     //camera rotated to point in positive Y axis direction
  11:     OutVT.POV.Rotation = Rotator(vect(0,100,0));
  12:  }

  • update player input computation method to react on forward/backward keys (SPG_PlayerController.uc):

   1:  function PlayerMove(float DeltaTime)
   2:  {
   3:     ...
   4:    
   5:     //CHANGE THIS:
   6:     NewAccel = PlayerInput.aStrafe * Y;
   7:   
   8:     //INTO THIS:
   9:     //aBaseY input is moving forward/backward, we want pawn to move along Y axis
  10:     NewAccel = PlayerInput.aBaseY * vect(0,1,0);
  11:   
  12:     ...
  13:  }


  • Compile, run, experiment :)!




Enjoy!

No comments:

Post a Comment