The Godot Barn
Sign in
Sign in
Home
News & updates
Explore
Tutorials
Articles
Snippets
Shaders
Submit content
Sign in to submit content
Give or get help
Questions
Conversations
Coming soon!
Recent snippets
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
autoload
ui
log
mesh
primitive
debug
fps
frames
camera3d
controller
crystal
mouse
Please wait ...
Okay
Okay
No
Yes
Okay