How can I handle Input in PlayerController?

My sample level does not use character or pawn (i.e. I just want to use the camera that comes with the PlayerController to fly around the level). More specifically, I want my controller to ignore pitch when moving around, the same way that moving with the left mouse pressed works in the editor. The examples that I can find all use a Character, which has some built-in methods (i.e. AddMovementInput) that are not available in PlayerController.

Has anyone else tried to implement this and, if so, could you let me know what you did? Thanks.

Hi Dijon,

Is your concern that you do not want to have a visible player character when you are moving around in your level? The “simple” solution would be to remove the character mesh from the character blueprint. That way nothing is displayed, but you still have the movement controls available.

To remove the character mesh, open the character blueprint and go to the Components tab. Select the Mesh in the Components hierarchy, then in the Details section, go to Mesh. Click the drop-down arrow that shows the name of the Mesh currently being used and select Clear from the menu that appears. That will remove the Mesh from the character Blueprint (you can easily put it back later by following the same steps). I would not recommend this for actual gameplay purposes (you would want to create your own character class without a mesh), but if you are using this in a sample level it should work fine.

The problem is not that I want to remove a visible character (I don’t have one that I’m controlling) but rather to handle player input via the PlayerController class. In the examples, there is always a pawn/character and so input is handled that way.

The solution that I found was based on a comment in the First Person Shooter tutorial which said, “The engine has a built-in class called DefaultPawn which is a Pawn with some simple disembodied flying movement.” I simply accessed that pawn’s Movement Component and, as described in the post “Problem with Constrain to Plane…”, I use:

movementComponent->SetPlaneConstraintNormal(FVector(0, 0, 1))

and toggle

movementComponent->bConstrainToPlane = true/false

when I want to stay at the same height or truly fly around. Hope this helps anyone else with the same problem.