Additionally, the platforms that are touching eachother are put into the same empty parent object which has a "Combine Children" script. This script takes all of the children objects (platforms) and combines all their meshes together. Therefore instead of rendering 6 different objects, only 1 object is rendered saving memory and enhancing game performance.
So far in our game we have the attributes of the level set and a few test-platforms to inhabit it however we're missing our main character! Introducing the prototype character that will be controlled by the user, "Capsule". Capsule isn't like any other default gameobject in Unity, through a little bit of tinkering I've managed to give it the basic movement controls it needs to explore the scene. This is done through the Platform Controller script I attached to it. What this specifically does is that it works alongside with the inbuilt CharacterController component Unity has and defines the physical mechanics within the environment. Additionally, through the Inspector pane on Unity I can optimize the variety of functions the Platform Controller Script inhabits, for example I can change the walk or run speed of the character or jump height, etc.
Even though we now have a simple character moving around an environment we need to introduce the Main Camera otherwise they will just walk offscreen! We need the Main Camera to do the following:
- We need the camera to follow the character but to also introduce the subtle movement when the character moves further in one direction. The camera in this game is much like the style of games such as Defender, this allows the player to easily view what is ahead of the level before they reach it.
- We also need the camera to track the main character when it jumps by adding a "springiness" property to the camera script. To make it not so jumpy for the player, it is preferred for the camera to not follow the complete motion for when the character jumps. By making the camera lag with the springiness property, we can stop it following the complete jumping motion
In order to achieve these objectives we can add the following scripts to the camera object.
Camera Scrolling: Allows the camera to move how we want with a distance property and a springiness property. The distance property (z-direction), sets the distance away from the target object (our main character).
Springiness Property: Stops the camera from following the complete jumping motion. The value itself defines how responsive the camera is to the target motion.
As well as the basic camera features we also have a few camera features set to our character, this script is called "CameraTargetAttributes".
Height offset: If set to 0, target will be sitting vertically center of the screen. If set to positive number, the camera will shift upwards which would create a vertically off-centre target.
Distance Modifier: We can modify the distance of the camera from the target, this setting adds onto the value that is defined in the camerascrolling script. (This functionality is good for multiple targets).
Vertically look ahead: Defines how quickly the camera shifts to look ahead when the target is moving.
Max look ahead: In order for the character not to leave the screen the value set here is the distance that the camera will stop looking ahead. X is horozontal distance whilst Y is vertical distance.
No comments:
Post a Comment