Setting up the player avatar
Different actors are created for different purposes, so actors need different combinations of components. For example, a player character may need a Camera component attached to it for the top-down view, whereas a building needs a collision box to prevent pawns from moving through it.
Writing a script to add components to a new actor needs four steps:
- Define a
privatevariable that will hold the component pointer. - Add the
publicgetter function, so that the component pointer can be retrieved outside of the class. - Include the added component’s header file.
- Instantiate the component in the class’s constructor function.
To set up the top-down view for the game, we want to attach two more components (SprintArmComponent and CameraComponent) to the player avatar.
Adding SpringArmComponent and CameraComponent to PlayerAvatar
The PlayerAvatar class already has the components inherited from its parent class, Character...