Decoupling the camera and actor

Heya LumberYard dudes and dudettes!

I thought I would get in touch because I am looking for a few pointers on third-person camera controls and modularising the shoddy code I am currently writing :slight_smile:

I’m currently using the FeatureTests solution as a base to play around with actors and cameras. I looked at the FlyCameraActor implementation and from that created my own ThirdPersonActor class which is my IActor implementation. I have physicalized it and plan to move it in a 2d plane using the WASD keys. This much I (vaguely) understand.

I’m now looking into pulling the first person camera back and out into an orbital camera. It would be nice to pull this out into its own class to separate the camera from the character. In the FeatureTests Actor.h file there is this little snippet:

 * #TODO
* This actor is also an IGameObjectView to simplify setup of a project.
* It is recommended that you create a GameObjectExtension or separate actor to
* function as your camera instead.

So what I did was stop Actor inheriting from IGameObjectView and added my own TPCamera class which will implement the relevant IGameObjectView functions, handle mouse input for orbital rotation and update the camera position and rotation appropriately.

class CTPCamera :	public CGameObjectExtensionHelper<CTPCamera, IGameObjectExtension>, public IGameObjectView, public IInputEventListener, public IActionListener

It is an IGameObjectView for the UpdateView functions, InputEventListener for the mouse action, IActionLIstener for any actionmap.xml stuff like maybe resetting the camera and then it is also an IGameObjectExtension; this is where I start getting really confused.

  • Should both the ThirdPersonActor and the TPCamera inherit from IActor?

  • Should the TPCamera just be an IGameObjectExtension?

  • Should I even be bothering with this entity system or be trying to use the new (but as far as I can see largely undocumented) component entity system?

  • If the TPCamera is not an IActor how should it be created? The ThirdPersonActor is created in OnClientConnect doing something like this: GetIActorSystem()->CreateActor(channelId, “Character”, “ThirdPersonActor”, Vec3(0, 0, 0), Quat(Ang3(0, 0, 0)), Vec3(1, 1, 1));

If you could shed any light, point me at any docs or code files I can peruse then I would be massively appreciative.

Thanks very much

Hi @FlyOnTheWingsOfThrash,

If you want to decouple the camera from the player, which is a good idea, I recommend you just call the actor something generic like “Player” or “Pawn” or something. Then make a CameraExtension that is set up like your CTPCamera and attach it to the player (aquire it). It’s your call if you want to make the camera extension support multiple camera rigs or not which would be more modular. You could instead make multiple camera extensions, one for 3rd person camera, one for 1st person etc - but if you want to transition between camera modes that can be tricky.

You could also break out the input into an PlayerInputExtension that collects the data and processes it into data for the camera or player to use - i.e. if the player presses ‘w’ then they want to move forward so send that data to the player to apply a physics impulse to the model or play an animation. If the player moves the mouse then pass the yaw data on to the player to rotate the model and pass the yaw data on to the camera to pitch the camera up and down.

Also, keep in mind with the new Component Entity system there are examples of doing this kind of thing with components, camera rigs and event buses. You’ll need to enable the following gems to get the components:

  • CameraFramework
  • Input Management Framework
  • Starting Point Camera
  • Starting Point Input
  • Starting Point Movement
    I’ve attached a level called ThirdPersonExample that shows the beginnings of how you would do this with components.

2198-thirdpersonexample.zip (39.3 KB)thirdpersonexample.zip

Thanks so much @petrocket. I’ll check that out this afternoon and will report back here. I have already done a bit of c++ stuff with the camera so may collate my findings for the next person to ask this question.