![]() ![]() Also please be aware that you can tweak the position of the Circle Collider 2D, or again add any other kind of collider to trigger the camera lock, this is just a mere example. You can go ahead and transform this in a full stack if you need that, but for our purpose since we don’t overlap multiple lock nodes this will do. The script will also remember its previous target so it can get back to it when the player is out of the trigger area. Then attach the following script to the player, that will allow it to temporarily switch the camera’s target to the lock node you’ve set. As the character moves and then leaves the POI’s trigger collider, we get back to another type of tracking, usually the standard follow behavior.Īdd the following property to the tracking script on your camera: public Transform TrackingTarget Whenever the character enters that trigger collider, we move the camera and stay on the POI. This can be achieved by configuring such POI in the scene and attaching a trigger collider to them. Having the camera move on lanes is great, but sometimes we need the camera to be locked on to something, a point of interest (POI) in the game scene. This implementation is not a WYSIWYG one, and is left as such as an exercise for the reader. ![]() Transform.position = new Vector3(, 圜oord, ) TargetYCoord = įloat 圜oord = Mathf.Lerp(, targetYCoord, ltaTime * followSpeed) The followSpeed is used here again for position interpolation, to prevent lane switching from being too abrupt: įloat targetYCoord = As the reference is positioned between a lane and another lane, the lower one of the two will be used to position the camera.Īnd the LaneSystem class takes care of moving the camera between lanes, based on reference position. Also assign the player character to the Reference field. Therefore, their positioning on the X and Z coordinates does not matter.Īdd the LaneSystem class to camera, along with the tracking class, and assign the lane objects to the provided array. ![]() We will use their Y position coordinate paired with Y offset in the tracking script above to implement the system. ImplementationĪ possible implementation is to add lanes as simple objects in the scene. Therefore, we need some limiters for specifying lane zones. Lanes’ levels can change throughout the game level based on the designer’s specific needs, or can be interrupted altogether and another camera tracking system can take their place. A lane should be changed only if the player’s character is going to stay on it for a while. While the character remains within the boundaries of this lane the camera will be moving only horizontally on lane specific height offset we can set.Īs soon as the character enters another lane, the camera will transition to that lane and continue to move horizontally from there on until the next lane change occurs.Ĭare must be taken on lane design in order to prevent fast lane switching during actions like jumps, which can create confusion for the player. The character is initially on the lower lane. The camera system we are building here is targeted at 2D platform games, but can easily extended to other types of 2D games, 2.5D games or even 3D games. ![]() It has a basic core consisting of several components which will ensure the basic functionality, and then various components/effects that can be optionally used, depending on the situation at hand. The camera system we are going to design together is modular and extensible. From 2D to 2.5D: An Extensible Camera System In this article I’m going to explain how to design a camera system for 2D games, and I’m also going to explain some points on how to go about implementing it in one of the most popular game engines out there, Unity. From just showing your game view in a chess app to masterfully directing camera movement in a 3D AAA game to obtain cinematic effects, cameras are basically used in any video game ever made, even before actually being called “cameras”. For a developer, the camera is one of the cornerstones of the game development process. ![]()
0 Comments
Leave a Reply. |