![]() AnchorDetector2D, is an area node we attach to the player to detect when it enters or exits an anchor area.When the player enters this Area2D, the camera’s target becomes this node’s location and zoom level. It smoothly follows the player by default unless the ship enters an anchor area. Although we keep it as a child of the player, we set it to be a top-level node, so it moves independently of its parent. AnchorCamera2D, the camera we attach to the player.We created three nodes to build the system: When entering and leaving specific areas, we change the camera’s target. The target can be the character the camera is attached to or any global position. In short, we have a camera that follows a target point using the arrive steering behavior, a vector math formula that makes an object smoothly move towards a target. Your browser does not support the video tag. Use steering behaviors to animate the camera’s zoom and position smoothly.Toggle anchoring the camera to the player or a fixed place when entering and leaving specific areas.Interested in continuing? Check out the full Godot Game Development for Beginners course, which is part of our Godot Game Development Mini-Degree.In this tutorial, you will learn to make the camera dynamically switch between following a character and anchoring to a given location. So if you press play now, you’ll see that the camera now tracks us along the X position but the Y stays the exact same like so. We just wanna go position dot X equals player dot position dot X, and this will track us along our X position. Then if we go func underscore process delta. Now, to do that, we need to go to the root of our scene, so we’ll go slash root slash main scene slash player, and this is gonna find our player node. So we’ll go onready var player, and this is going to be equal to get underscore node, and we wanna find the player node. So all we’re gonna do in this script right here is two things. There we go.Īnd now what we can do is, if we go to the Inspector, we can create a new script for this camera, so we’ll go new script here, and I’m gonna rename this to Camera Controller. So we’ll drag it–we’ll select the camera here, and we’ll drag it down to here, where it overlays the existing camera. So in order to do that, let’s first of all move our camera over to where we want it to be initially. Now if we press play, you’ll see that the camera has changed, but right now, it is not moving to track our player. Make sure Current is enabled, and you’ll see that the blue outline suddenly glows. So what we can do is, we can actually have this camera override the existing preset window, which is what we see into the world, by going over to the Inspector with the Camera2D selected and click on Current. Now, this Camera2D, as you can see, it appears in our main scene, and it has that blue rectangle similar to the one that already exists. So in our main scene here, I’m gonna create a new node, and this is gonna be of type Camera2D. In this lesson, we’re gonna be creating a camera in Godot and having it track our player horizontally. The camera now tracks us along the x position. Save the script and press the Play button. Onready var player = get_node("/root/MainScene/Player") What we have to do inside the script is simply find our player by using get_node( ), and then set the camera’s x position to be the same as the player’s x position. Click and drag the camera to where we want it to be initially.Ĭreate a new script inside Camera2D and name it as CameraController. Now, let’s make our camera to track our player. You will see that the blue outline appears in the viewport, showing the range of the current camera. Select the Camera2D and enable the ‘ Current‘ property in the inspector. In this lesson, we’re going to be creating a camera in Godot and having it track our player horizontally.Ĭreate a new node of type Camera2D in the main scene. You can access the full course here: Godot Game Development for Beginners
0 Comments
Leave a Reply. |