Devlog 4: Auto Camera
This week will be a very simple implementation that affects the camera and how the player moves while the camera resets.
It's hard to explain without showing code.
Simply put, the camera rotates back to one of four presets NSEW positions, whichever the camera is closest to when the reset begins. The camera won't rotate until you haven't given any input for two seconds.
An issue I came across after implementing this was that as the camera reset, if you were running in a direction and the camera reset to a target position, the direction you ran into would reset too. I didn't like this, if I were running in a direction and not turning the camera or control stick myself, I probably didn't want to change direction. I assumed that was how most people would feel, so wanted to allow you to keep moving until you stopped giving input/put input to a new direction/changed the camera yourself.
So to start, let's look at the code that rotates the camera.
After a 2 second countdown of no input, ResetCamPos is called, which calls four rotate functions, each taking in the camera heading, which is the a variable that the camera's location around the player is based on. Passing in two bounds, and the centre axis point for those bounds, allows us to check if the heading is less than the target angle but greater than the lower bound, and vice versa for the higher bound. After that the header is increased or decreased by a smoothing.
There is a buffer of .5f for checking if the heading is already inside the target point, because we are using delta time and therefore won't get nice and easy integers to measure by.
While the player is in 3D level mode, it checks if the there is any camera input, if there is, then countdown is reset and the heading and tilt are changed by the input of the player. The heading logic is what we are interested in here. the 405->45 relation is to keep the heading within a reasonable number on the rotation. Initially it was a 0->360 relationship, but this made it difficult to reset the axis on the 0 angle. Changing it to 405->45 alleviated this problem and allowed me to use the rotate function for all four axes.
This script does the usual commands shown in devlog 1, but with an added condition. multiple coniditions are present to check if the player is not giving input, or giving input to the camera. If they are doing either of those two things, the camera reference points update. I say reference points because the player's movement is based on these references.
If these reference points don't get updated when the camera does, the player will still be moving based on the old camera location. So it's a simple case of not updating until the player chooses to with a change in input or an input to the camera.
That's how I implemented this really easy feature! :)
Gameplay Programming
work on gameplay programming
Status | In development |
Author | JacobDWoodman |
More posts
- Devlog 7: Group ProjectApr 19, 2020
- Devlog 6: CombatApr 01, 2020
- Devlog 5: Moving PlatformsMar 31, 2020
- Devlog 3: Doors and Switches(actually Buttons)Feb 18, 2020
- Devlog 2: Collectable BoogalooFeb 06, 2020
- Devlog 1: PlayerJan 27, 2020
Leave a comment
Log in with itch.io to leave a comment.