Code Snippet of the Week: CryEngine2 Third Person Camera

Recently I have been employeed at a new company where I work with the CryEngine2 quite frequently. CryTek has released a MOD sdk for their popular Crysis Wars game. In my personal time, I enjoy developing mods for this amazing game. Crysis Wars is a first person shooter game thus the camera by default is set in a first person perspective.

First person perspective

First person perspective

One of the very first mods I wrote for the CryEngine is a Third Person Camera. The CryEngine already supports a third person camera however a developer using Flow Graph is limited as to what they can do with it. For example, the third person camera is at a fixed distance away from the player. A developer can’t really control this at all. That is why I decided to write my own custom flow node for the CryMOD sdk that would give developers the ability to use a flexible third person camera system. Below, you can see a demo of my third person camera as well as the source code.

Third person perspective

And here is the source code.

// FlowThirdPersonCameraNode.cpp
// Purpose: This flow node gives the developer
//	    more flexibility of controlling
//	    the third person perspective 
//	    camera by allowing them to offset
//	    the camera's distance from the player.
// File History:
// - 6/05/09 : File created - Brandon Fogerty
#include "StdAfx.h"
#include "Nodes/G2FlowBaseNode.h"
#include "Cry_Camera.h"
#include "Actor.h"
class CFlowThirdPersonCameraNode : public CFlowBaseNode
	enum EInputPorts
		EIP_SYNC = 0,
	CFlowThirdPersonCameraNode(SActivationInfo * pActInfo)
	virtual void GetConfiguration(SFlowNodeConfig &config)
		static const SInputPortConfig inputs[] = 
			InputPortConfig<float>("distance",-7.0,_HELP("Distance from player")),
			InputPortConfig<float>("height",2.0,_HELP("Height relative to the player")),
		config.pInputPorts = inputs;
		config.pOutputPorts = NULL;
		config.sDescription = "Control the third person perspective camera.";
	virtual void ProcessEvent(EFlowEvent evt, SActivationInfo *pActInfo)
			case eFE_Activate:
				if(IsPortActive(pActInfo, EIP_SYNC))
			case eFE_Update:
				// Grab the game's camera view.
				CCamera cam = gEnv->pSystem->GetViewCamera();
				// Get the local player
				IActor * pActor = g_pGame->GetIGameFramework()->GetClientActor();
				// If we are in a vehicle,  use the default camera system.
				if(pActor->GetLinkedVehicle() == NULL)
					// We need to toggle the regular third person camera
					// so that crysis renders the whole player model and
					// not just the limbs.
					if(pActor->IsThirdPerson() == false)
					// Get our camera's position
					Vec3 vecCamPos = pActor->GetEntity()->GetPos();
					// Offset the camera on the z axis (Up/Down)
					vecCamPos.z = pActor->GetEntity()->GetPos().z + GetPortFloat(pActInfo, EIP_HEIGHT);
					float fDistance = GetPortFloat(pActInfo, EIP_DISTANCE);
					// This is a little math to which ensures that our camera is always facing the direction
					// that our player is looking.
					vecCamPos.y = pActor->GetEntity()->GetPos().y + (pActor->GetViewRotation().GetFwdY() * fDistance);
					vecCamPos.x = pActor->GetEntity()->GetPos().x + (pActor->GetViewRotation().GetFwdX() * fDistance);
					// Override the crysis camera with our newly calculated camera view and we are done!
	virtual void GetMemoryStatistics(ICrySizer *s)
	virtual ~CFlowThirdPersonCameraNode()

Well that is it for this week. You can also find this code snippet on the official CryMod website at

I hope that this makes sense and helps you get more out of the CryEngine! Happy modding!

Did you find this article useful?

View Results

Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.