UE Blueprint God View
The UE5 blueprint realizes the control of the camera's God's perspective, including rotation around the point, horizontal translation, and zooming in and out
achieve effect
Rotate around a point
horizontal translation
Realize function
- Left mouse button translation (translation relative to the horizontal plane of the scene)
- Right rotate around point
- The middle key angle of view moves back and forth (can be understood as zooming)
implement logic
- Rays
The camera emits rays to the ground, and returns the hit point and the distance to the hit point.
Considering that the collision point may not be obtained, the height of the camera and the angle of the camera are used to simulate the collision point with the horizon.
- translate
Use the angle between the Camera and the horizontal plane to calculate the vector in the horizontal direction, so as to realize the translation of the horizontal plane of the scene; use the ray to return the length from the camera to the hit point, so as to control the moving speed of the camera.
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-m0WroDbY-1677818341832)(null)]
- Rotate around a point
Rotation around a point is divided into two parts, camera rotation and camera displacement. Rotation achieves its own rotation by accumulating the Y (Pitch) and Z (Yaw) values of the camera itself through MouseY and MouseX; displacement uses rays to return to the camera hit point
- move back and forth
It is relatively simple to move back and forth, and you can directly get the ForWard method of the camera.
For details, see unity Camera control (God's perspective)
other controls
some variables used
Assignment of control keys
main control
get a camera