Overview
Visualizing velocity is one of the most common uses for VectorDisplay2D. This example shows how to display a character’s velocity vector in real-time, making it easy to debug movement mechanics and understand motion behavior.Basic Setup
Here’s a complete example of a CharacterBody2D script with velocity visualization:Scene Tree Structure
Set up your scene hierarchy like this:Configuring VectorDisplay2D
Select the VectorDisplay2D node and configure these properties in the Inspector:Target Properties
| Property | Value | Description |
|---|---|---|
| Target Node | .. (parent) | Points to the CharacterBody2D |
| Target Property | velocity | The Vector2 property to display |
| Settings | Create new VectorDisplaySettings | Click to create a new settings resource |
Settings Configuration
Create a newVectorDisplaySettings resource and configure it:
Advanced: Speed-Based Dimming
Make the vector fade when the character slows down:Settings with Dimming
- Fast movement = Bright yellow vector
- Slowing down = Vector fades to gray
- Stopped = Nearly invisible gray vector
Tips for Best Visualization
Scaling
Adjust
vector_scale based on your game’s velocity values. If velocities are in the hundreds, use 0.1-0.5. For smaller values, use 1.0-2.0.Clamping
For high-speed games, set
length_mode to “Clamp” and max_length to 150 to prevent vectors from extending off-screen.Runtime Toggle
Press
Shift + V during gameplay to toggle vector visibility. Perfect for debugging without cluttering the screen.Axes for Platformers
Enable
show_axes in platformer games to separately visualize horizontal movement (X axis, red) and gravity/jumping (Y axis, green).Complete Example Scene
Here’s a full working example with optimal settings:Complete Setup
Use Cases
- Debug character movement - See exactly how fast your character is moving
- Visualize physics - Understand how gravity, friction, and acceleration affect motion
- Test jump mechanics - See the velocity arc during jumps
- Identify movement bugs - Spot unexpected velocity changes instantly
- Balance game feel - Adjust speed values while seeing real-time feedback
Next Steps
Acceleration Vectors
Learn to display multiple vectors like velocity and acceleration together
Custom Styling
Explore advanced visual effects like rainbow mode and creative color schemes
