Godot camera2d6/15/2023 ![]() But I am not sure of a good way to implement it. I imagine I can achieve this by defining different rectangular shapes in my level and setting the camera limits when my player enters these shapes. For example, if the player is in a narrow corridor, the camera wouldn't scroll up or down. using the sides of the rectangle).īut what kind of node should I use? Area2D perhaps? Or maybe a ReferenceRect would be easier.Įventually, I'd like my level geometry to dictate the limits of the camera on a sub-level basis. When a level loads, I can access this node and set the limits of my camera using it (setting the camera's limit_left, limit_top, etc. ![]() I was thinking that I could have some kind of rectangular node per level. What is a good method for setting rectangular camera limits on a level-by-level basis? Interested in continuing? Check out the full Godot Game Development for Beginners course, which is part of our Godot Game Development Mini-Degree.I want to set the limits of a Camera2D attached to my player on a level-by-level basis, but I am not sure of the best method to do this. ![]() 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. Run far enough to the right that the camera starts scrolling and stop. 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. A simple implementation of Godots Camera2D uptimized for touch inputs - GitHub - williambcosta/godot-touch-camera-2d: A simple implementation of Godots. 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. 1 Answer Sorted by: 0 Probably the simplest way to do it is to use a CanvasLayer (or multiple CanvasLayer ). 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. |