Creating a custom camera
For the purpose of this game, I don't need a camera following the player pawn, as it would do in a 3rd person game: I'm going to have a fixed camera that will show the whole game map from a static point of view. Let's see how to create it:
First, go to Modes > All classes > Camera and drag a new camera into your scene.
I positioned it manually, moving and rotating it until it looked at the whole map from a satisfying angle. As you can see, when it's selected, a small box on the lower right corner of the editor shows the camera's point of view.
I positioned it manually, moving and rotating it until it looked at the whole map from a satisfying angle. As you can see, when it's selected, a small box on the lower right corner of the editor shows the camera's point of view.
When I'm ok with the position, I type in the round values for Location and Rotation in the camera properties:
Now, what we have to do is tell Unreal that we want the game to start from that particular camera (we could have multiple cameras in our scene), and this can be done inside the Level Blueprint.
With the camera selected, open the Level Blueprint. If you right-click inside the graph editor, in the first lines you'll see "Create a reference to CameraActor". This will tell the Blueprint what is the instance of the object currently selected.
Next, we want to pass this instance to the function "Set View Target with Blend". The camera is used as input to the "New View Target" parameter of the function.
We need another input, the "Target" player controller. We have created a custom Player Controller class, so how to reference it? Again, Unreal is very helpful and gives us the Get Player Controller function, that returns the current Player Controller used in the scene. Note that the function uses an index, because in multiplayer games there could be different Player Controllers at the same time. This is not our case, so let's just leave the value 0 for the default Player Controller. Plug the output to the "Target" input of the function, leave all the other values to default and don't forget to trigger the execution of the function, chaining it to the BeginPlay Event; hopefully, when you launch the game it should show the complete Main Map as seen from the camera.
We need another input, the "Target" player controller. We have created a custom Player Controller class, so how to reference it? Again, Unreal is very helpful and gives us the Get Player Controller function, that returns the current Player Controller used in the scene. Note that the function uses an index, because in multiplayer games there could be different Player Controllers at the same time. This is not our case, so let's just leave the value 0 for the default Player Controller. Plug the output to the "Target" input of the function, leave all the other values to default and don't forget to trigger the execution of the function, chaining it to the BeginPlay Event; hopefully, when you launch the game it should show the complete Main Map as seen from the camera.
The Set View Target with Blend function can also, as the name suggests, blend the view point from one object to another, moving in a specified time and using different functions. We could use this, for example, to move at the beginning of each level from a close-up of our Player ship to the global view point, just to add some nice movement to our gameplay.
As I said before, let's concentrate on the main functionalities for now, taking care of these details later in the developement.
Game you next time!
Commenti
Posta un commento