Next in the series Game programming with Godot, today I will guide you to create a character tracking camera. When the character moves on the screen, we will easily follow our character.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
Let’s get started:
Camera
In the previous post you did, you will see when running the game it will look like the picture
And this is after the camera
How to create a character tracking camera
So today I will guide you to create a camera for your character.
First in Player you find and create for yourself Node Camera2D
Then you zoom out to notice that you will see 2 squares:
- 1 piece below is incomplete.
- the one above is complete and The complete one is your camera frame.
If you run the game it stays the same so we need to edit again settings of the camera
Open your own section Limit beside setting camera2d
What is Limit? Limit is the limit of the camera, for example left is the coordinate that it will go to the left
To make it easier to understand, please pay attention to the picture below
The vertical green line is the number 0 and that is coordinates x and the red line going to the left is y . coordinates
VD: You want the camera move to 0 x-axis is to stop and not move, you can edit it in the box Limit part left is 0
Ah must turn on Current it just works
When you turn it on, you will see a change and if you turn it on, you won’t see anything so let’s continue
Part top I also let 0 so that it doesn’t go over the red line
Part Botton I let 325 and how to bottom setting
Friend zoom up the part you want it to be limited to bottom
You guys keep looking for landmarks and then zoom When you go up, you will see the number in the left column and then fill it in bottom like photo
And then adjust the zoom X 1 – Y 1 -> X 0.5 – Y 0.5
Run the game and you’ll see the difference
And you can see our game screen has changed
If you think it’s too big, adjust it 0.6- 0.8 Please. If you do not want to adjust but see it as large, just adjust the Player to be smaller.
And one more part is that if you pay attention, you will see when you move, the camera moves along and in godot also supports you to add a mode that when you move a segment, the camera will move.
That is the part: Drag Margin H – Drag Margin DRAW
Click on those 2 you will see the difference.
And when you move, you will see that when you reach a position, the camera will move according to the character, so is there a way to adjust the position limit so that the camera will move the character? And of course there are you guys looking for yourself Drag Margin live settings camera
And it will not show a frame telling you how limited it is, so you can turn it on for yourself as follows:
Find Editor > enable Draw Drag Margin okay and it will be displayed and you can edit it as you like
So, I have finished the guide to monitoring the character screen by configuring the Camera. You should see from post 0 Go to this post for easy steps.