Crafting a Paraboloid Camera Controller
Crafting a Paraboloid Camera Controller
Smooth Moves and Perfect Views (hopefully!)
Now that I'm able to create a new character, and visualize it in a scene, I need a camera to explore the world.
While playing Baldur's Gate 3, I was struck by how smooth the camera movement felt, especially during exploration and combat.
To be honest, I found the camera in Baldur's Gate 3 occasionally struggled during combat, particularly when characters and enemies were on different elevation levels. In vertical or multi-layered environments, it sometimes had trouble maintaining a clear and useful view.
Still, overall, the experience was solid, and there are definitely some ideas worth borrowing. In fact, I realized I could build a custom camera controller inspired by that approach.
In BG3, the WASD keys move the camera across the XZ plane in world coordinates, the middle mouse button rotates it around a focal axis normal to the XZ plane, and the scroll wheel controls zoom. What stood out to me was the zoom behaviour: instead of moving the camera in a straight line, it seems to follow a curved path, almost like a parabola. When this motion is combined with rotation, the camera appears to glide along a 3D surface that resembles a paraboloid of revolution.
That idea stuck with me. I started experimenting, and the result is my Paraboloid Camera Controller, a custom camera system inspired by that cinematic, orbital feel.
Here’s an overview of what was done:
The Concept
The goal was to create a camera controller that constrains a camera onto a paraboloid surface defined by the equation:
y = (1 / a) * ((x - Cx)² + (z - Cz)²) + Cy
where C: (Cx, Cy, Cz)
is the paraboloid center, a
is a coefficient of convexity: the higher a
is, the flatter is the paraboloid convexity.
This means that the camera's height is a function of its distance from the vertical axis passing through the center point. The shape gives a natural, curved trajectory for the camera to move along, perfect for scenes involving large open vistas or top-down exploration, like RPG or Strategy games.
Key Features
Here are the highlights of the work I’ve done to bring this camera controller to life.
Paraboloid-Based Movement:
- The camera moves along a paraboloid surface, with the ability to adjust the coefficient of the curve (
1/a
) to control its flatness or steepness. - The paraboloid can be repositioned in the XYZ space.
Height and Rotation Control:
- Configurable range for minimum and maximum camera height above the paraboloid's center.
- Smooth camera rotation around the center point based on user input, with support for continuous transitions during angle changes.
Smooth Transition Handling:
- Integrated smoothing for movement, height changes, and rotation transitions.
- Adjustable smoothing rates for height, movement, and rotation, allowing for fine-tuned responsiveness.
User Input Integration (via Unity's Input System):
- Camera controls respond to user inputs, including:
- Move Input (e.g., W/A/S/D for position adjustment on the paraboloid).
- Sprint Input for faster movement using a sprint multiplier.
- Mouse Input for rotating and controlling horizontal movement.
- Scroll Input for vertical height adjustments.
- Inputs are carried out through Unity's
InputAction
system with custom binding support.
Configurable Camera and Settings:
- Option to assign a specific camera or use
Camera.main
as the default. - Automatically positions and orients the camera to look at the paraboloid's center.
Adaptable Camera Dynamics:
- Decoupled movement modes for horizontal and vertical control, making it easy to script specific use cases.
- Calculates the camera's position based on polar coordinates (`radius` and `angle`), dynamically converting these to Cartesian coordinates.
Center Point Movement:
- Supports smooth center point transitions with configurable speeds.
- Center point adjusts based on input, such as keyboard-based movement or custom-defined dynamics.
- Sprint multiplier allows faster repositioning of the paraboloid's center.
Error Handling and Validation:
- Ensures configuration values like height limits and the coefficient are valid at runtime.
- Logs warnings for missing components or configuration errors.
Customizable Speed and Smoothing:
- Parameters to configure horizontal movement speed, vertical movement, and rotation responsiveness.
- Fine adjustments through exposed fields like movement speed, rotation smooth factor, and height smooth factor.
Real-Time Updates:
- Continuously checks for user input or changes in position/rotation, ensuring dynamic updates while maintaining efficiency by skipping redundant recalculations.
The Result
You can see the Paraboloid Camera Controller in action in the following short video:
Final Thoughts
If you believe all the math you studied in high school and university has no real-world use, here's an example that proves otherwise.
This camera controller is still in development and has never been used in a real game. I'll keep testing it and improving it based on my needs and maybe on day I'll make a proper package.
If you’re working on a game or project that could benefit from this controller, I’d love to hear about your experience or provide any help! Feedback and suggestions are always welcome.
Here you find the source code (at the time of writing): Assets/Scripts/Management/Scene/ParaboloidCameraController.cs
Stay tuned for future updates, and happy developing! Ciao!
DeeDeeR
D&D SDK based on SRD 5.1
A modular and extensible SDK for implementing Dungeons & Dragons-style RPG mechanics in Unity
Status | In development |
Category | Tool |
Author | Dee-Dee-R |
Tags | csharp, Dungeons & Dragons, Ludum Dare 57, sdk, Unity |
Leave a comment
Log in with itch.io to leave a comment.