camera 2D
version 3.5.2 topic Camera2D
So how to use the camera 2D mode properly without scratching the hairs out due to misunderstanding. Let’s begin.
First the easy parts where you only set gadgets on the camera component.
- set the camera as “current” this helps to fix the camera at the player
- put Camera2D node under the Player node and it will fix the center on it.
- make the camera flow behind with smoothing enabled “true”
- for pixel zoom when you have a 800x600 resolution set the “zoom” of camera to 0.5 for both x an y values and it will be bigger
How to fix the camera to follow player but stay inside the scene bounds. 1.It is not automatic that the engine knows the level size limits as x1,y1,x2,y2 boundaries calculated somehow. 2.So add a Camera2D node after the player and just set the limits you need there. 3.Then attach a script to the camera and put inside this code
extends Camera2D
# the basic thing about a camera component is to set the scene boundaries for player and some moving npc
func _ready():
# store camera limits for the scene
Basic.setSceneLimits(limit_left,limit_top,limit_right,limit_bottom)
4.Basic is the library i made that has functions that register the camera limits. Then out of there inside the Player component i can test each move the limits of the movement and clamp it. Propably you will not know ho to set up a library inside the Godot engine. So look in project/setting/autoload tab and put a library script you make there.
NOTE: This was the easy way of doing such limitation on player with a camera. Maybe later i understand a better way that will not break some rules of coding.
Godot - game development for homies
Status | Released |
Author | Bastian |
Genre | Educational |
Tags | Godot |
More posts
- loading resources with gdscript4 days ago
- i was wrong!7 days ago
- physics collision and layers7 days ago
- tool ghosts8 days ago
- storing player position8 days ago
- component campfire8 days ago
- how to control things in a scene component9 days ago
- component : fadein10 days ago
- blocking my view eh?10 days ago