Cutscenes Complete! Lights, Raycast, Action!
Day 20- 11/18/20
Today is day 3 since I have been on the cinema course and I have completed about two-thirds of the course work so far. I have completed all 4 cutscenes, and am now working on the actual game part of the program. Learning about the cinematic side of gaming was an awesome experience and felt like a nice breath of fresh air, but I am excited to get back into the programming side of things.
To start the day, I didn’t have much left for the cinematics. I basically had to go through and polish up my intro cutscene and make sure that the transitions and shots were matched up with the audio. Nothing crazy here.
My next goal for the day was to complete the Player movement section. Learned some very creative techniques regarding triggers and cameras to follow the players’ progression through the level. Taking a step back, I also learned a lot about setting up the environment for a 3d game to make sure the player object knows where the floor is, and also where other static objects within the scene are located.
Just gonna re-hash a few processes over the next few paragraphs to help engrain what I have learned today and hopefully help someone out.
NavMesh
The purpose of the Nav Mesh is to allow objects within the game, such as our player object, to know where in the scene important objects are such as the floor and other objects you may not want your player to collide with, in this instance, the detailed models in our scene such as the glass cases. In the picture above you can see the Nav Mesh in blue, and if you look at the glass cases, you will see a border around each case to prevent the player object from going through and clipping the cases.
When you add a Nav Mesh Agent to an object, such as our player object, this allows the player to now know where the floor boundary is located and will snap the player to the floor. Overall, very awesome and useful feature, as I have always wondered how games set the floor boundary.
Camera Trigger
The use of camera triggers to trigger multiple camera angles to follow the player object through the level is a really cool and creative implementation to create a 3d game such as this. The camera triggers are basically just clear game objects on the floor, and with a collision trigger similar to the 2D shooter, you can detect when the player reaches a certain point within the game. In the picture above you can see the trigger on the ground (the green invisible rectangular box).
So, how do these triggers work?
First, the triggers on the ground need to be given the trigger feature as well as a rigid body to detect collisions with the player object. From here you can script an OnTriggerEnter feature to be added to the lifeless and currently functionless boxes on the ground.
Create a public transform variable to store each camera position in order to set the main camera position to the desired camera. And to make sure each camera position is associated with the correct trigger, make sure to drag the camera you would like to transition to in the triggers inspector.
Once you have your OnTriggerEnter set up to detect collisions with your player, and a variable to store your camera positions, you now just need to set the main camera position and rotation equal to the camera transform associated with the trigger activated. For reference, I uploaded a picture of my script.
One feature I would like to add to the camera trigger is to create a function that allows the camera to go backward in the level if the Player crosses back over the trigger. I was thinking of doing this with a trigger collision as well as a comparison of the players' transform.position.x value.
Player Movement
To control player movement I used raycasting to set the point for the player to move to. Raycasting is still a very new concept to me so I am still trying to understand how to properly utilize it. From the scripting reference a raycast:
RaycastHit hitInfo;
Will return if the RaycastHit collides with an object.
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
ray is a variable that is storing the position of our main camera at the time of the input, which will be whenever the left click is pressed.
_agent.SetDestination(hitInfo.point);
Is a handle from our player Nav Mesh Agent and the rest of the line tells our player to move to the location of the raycast collision which is hitInfo.point.