As of the 14th of March, we started to get into groups with students from other games classes for a collaborative project on a game with the theme of “A conversation that changes the world”.
After brainstorming several ideas with the group, we had the idea to create a top-down game in the style of a bullet hell. Where the player will be avoiding projectiles from a birds eye view.
To get started on the project, I started work on the prototype by creating some basic movement and a camera that changes from room to room via the use of box component triggers, Figure 1 shows the system in place.
To do this I set up an Actor that contains a box component and uses an onOverlapBegin function – included is also a boolean that activates a camera on start.
This is used as a trigger that covers a whole room, and once overlapped will trigger a function that sets the player controller’s current view target with an assigned camera – as seen on the bottom of Figure 2, we have an actor reference we will be using.
Figure 3 shows the actor reference is used to select any camera within the environment, this will then be referenced within the CPP section of our code.
There is also a UPROPERTY with EditAnywhere assigned to it, this is so that we can easily assign it to any camera in-editor – this helps let other people working on the project to easily do this themselves without having to code.
Before we set a view target on our cameras, we need to possess the player within our scene. This is done by including “Kismet/GameplayStatics.h” in our CPP file.
We need to possess the current player by doing UGameplayStatics::GetPlayerController(this, 0). This will get the first player in the game scene.
Harrison McGuire, 2017
Within the CPP file of the actor is an overlap begin function. First included is a debug message to confirm that our overlap event is working, secondly is a local variable used to set the time of the camera blend – this is used to make it so the camera transitions smoothly to the next.
We then include a reference to the player character to detect if they’re colliding with the trigger, then once we find the actor that handles control for the local player we get the view target of the player’s current camera and set it to move to our referenced actor.
As shown by figure 6, this is the player walking into a room with a different trigger. Once overlapped, the viewtarget is set towards the camera assigned to the trigger – the image shows the blend in motion.
Unrealcpp.com. 2017. Unreal C++ | Set View Target. [online] Available at: https://unrealcpp.com/set-view-target/ [Accessed 24 March 2022].