Changing the player camera through key input

In this recipe, we will look at a simple setup to allow the player to switch from the First Person view to the Third Person view.

Getting ready

Open My_Level.cry within the Sandbox

How to do it...

  1. Begin by placing an AreaTrigger entity onto the map to use as the container for the Flow Graph.
  2. In the RollupBar, click on the Entities button.
  3. Under the Triggers section, select the AreaTrigger.
  4. Right-click the newly placed AreaTrigger and create a new Flow Graph. Name the Flow Graph as PlayerViewToggle.
  5. With the Flow Graph open and the new AreaTrigger selected, add in the following nodes:
    • Game:LocalPlayer
    • Input:Key
    • Logic:Sequentializer
    • 3x System:ConsoleVariable
    • Misc:Start
  6. Set the input Key = g.
  7. Set all three System:ConsoleVariable Cvar=g_tpview_enable.
  8. Set one System:ConsoleVariable Value=1.
  9. Link the Flow Graph together as follows:
    • Game:LocalPlayer entityId out to Input:Key Choose Entity in
    • Input:Key Pressed out to Logic:Sequentializer In in
    • Logic:Squentializer Out1 to System:ConsoleVariable Set in (this needs to be g_tpview_enable = 1)
    • Logic:Sequentializer Out2 to System:ConsoleVariable Set in (this needs to be g_tpview_enable = 0)
    • Misc:Start output out to System:ConsoleVariable Set in (this needs to be g_tpview_enable = 0)
  10. The resulting Flow Graph should look like the following:
    How to do it...

How it works...

This Flow Graph has an input listener that waits for the specific key to be pressed by the entityId it is assigned (in this case, the player). Once this key is pressed, it will toggle the console variable that enables Third Person view. The Misc:Start to force set the CVar is a preventative measure to make sure the player is in First Person on Game Start.

This is not an ideal method of modifying the view of the player for final release as this should actually be done in code. However, this Flow Graph will do the job until code can perform this same function.

There's more...

An alternative camera to the standard Third Person view is the goc_camera, which by default hangs over the right shoulder of the player. Explore the goc_camera's capabilities with the following CVars:

  • goc_enable
  • goc_targetx
  • goc_targety
  • goc_targetz
  • g_tpview_force_goc
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.157.34