0 votes

How do I make a camera2d that follow player but only stay inside certain area such as area2d (camera seen from megaman or metroid). I would appreciate if you could teach me how to implement such camera2d. Red line is area2d and camera2d only stay within area2d.

enter image description here

I have looked at mega-man-engine available at github, as they keep camera2d within reference rect, but it was beyond my understand to fully understand how the camera2d is controlled with my few knowledge and experience in coding. I have also looked camera flip screen template published by chucklepie and thought this could be very useful for my project. However, it didnt work somehow, though I followed his tutorial.

Godot version ver3.3.3
in Engine by (80 points)

1 Answer

0 votes

You can set the limits of the camera in both the vertical and horizontal in script. If you look at the Platformer2D demo, there's a level script that limits the camera extents in _ready().

by (141 points)

Thank you zenbobllly! Can it be used in area entered function??
Like setting a different value of camera.limit for each area, so that I can change the camera limit several times in a scene.

You can do that or you can move the camera along a fixed path using AnimationPlayer or defining a path. I suggest you read the Camera2D documentation to learn the properties you can modify to change the way the camera moves. You can also change its position directly in script.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.