The Godot Barn
Sign in
Sign in
Home
News & updates
Explore
Articles
Snippets
Shaders
Themes
Submit content
Sign in to submit content
Give or get help
Tutorials
Questions
Conversations
Coming soon!
Recent snippets
0
3
class_name RTSCamera2D extends Camera2D @export_group("Zoom", "ZOOM_") # These control the maximum zoom in and out levels. This means a maximum zoom in of 2x and a zoom out of 100x (0.01) @export_range(0, 5, 0.01, "suffix:times", "hide_slider") var ZOOM_MAX: float = 2.0 @export_range(0, 5, 0.01, "suffix:times", "hide_slider") var ZOOM_MIN: float = 0.01 # Control how quickly we zoom in and out by a factor of @export_range(1, 10, 0.5) var ZOOM_SPEED: float = 2
RTS Camera 2D
xsist10
Jan 12th, 2025
Provides a configurable basic RTS Camera 2D that supports zooming and panning.
Godot
4.2
GDScript
camera
camera2d
rts
1
2
// Get upper-left and lower-right positions of the viewport in world coords Transform2D InvCanvasTransform = GetTree().Root.CanvasTransform.AffineInverse(); Rect2 viewportRect = GetViewport().GetVisibleRect(); Vector2 upperLeft = InvCanvasTransform * Vector2.Zero; Vector2 lowerRight = InvCanvasTransform * viewportRect.Size; // The clamped position is an easy way to check if the target is off-screen. Vector2 ClampedTargetPosition = Target.Position.Clamp(upperLeft,lowerRight);
Positioning a pointer to off-screen objects
Keith Jones
Dec 18th, 2024
We show how to position an "edge of screen" pointer from a source position to an off-screen target position with vector calculations.
Godot
4.2
C#
visible rect
viewport
canvastransform
pointer
Filters
Contents containing
Language
GDScript
C#
Both
License
All licenses
CC-BY
CC0
GPLv3
AGPLv3
MIT
Unlicense
Godot version(s)
All versions
Godot 3.x
Godot 4.x
Godot 4.0
Godot 4.1
Godot 4.2
Godot 4.3
Godot 4.4
Reset filters
Apply filters
Popular tags recently
functions
first-person
bus
UI
log
mesh
primitive
debug
frames
camera3d
controller
behavior
boids
flock
graphics
Please wait ...
Okay
Okay
No
Yes
Okay