如何让场景中的Camera Node跟随可操纵的Plane Node移动?
Hey there! Let's get that camera stuck to your plane so it never drifts out of view while you're flying with the joystick. Here are some easy-to-implement solutions, starting with the most common scenario in Unity:
This is the simplest fix—just lock the camera's position to your plane's position plus a fixed offset:
- Create a new C# script named
CameraFollowand attach it to your Camera Node. - Paste this code into the script:
public Transform planeTransform; // Assign your Plane node here in the Inspector public Vector3 cameraOffset; // Adjust this to set your desired camera angle/distance void LateUpdate() { // Update camera position to match the plane's position plus your offset transform.position = planeTransform.position + cameraOffset; // Optional: Make the camera always face the plane transform.LookAt(planeTransform); } - In the Unity Inspector, drag your Plane node into the
planeTransformfield of theCameraFollowcomponent. - Tweak the
cameraOffsetvalues (try something like(0, 6, -12)for a nice behind-and-above view) until you're happy with the perspective.
If you want the camera to ease into position instead of snapping instantly (great for a more cinematic feel), modify the script like this:
public Transform planeTransform; public Vector3 cameraOffset; public float smoothFollowSpeed = 0.15f; // Lower = slower, smoother follow void LateUpdate() { Vector3 targetPosition = planeTransform.position + cameraOffset; // Lerp between current camera position and target position for smoothness Vector3 smoothedPosition = Vector3.Lerp(transform.position, targetPosition, smoothFollowSpeed); transform.position = smoothedPosition; transform.LookAt(planeTransform); }
- Play around with
smoothFollowSpeedto find the right balance between responsiveness and smoothness.
The core logic stays the same—tie the camera's position to the plane's position with an offset:
- Unreal Engine: Use a built-in
Follow Cameracomponent (attach it to your plane, then adjust the offset in the component settings), or create a Blueprint that updates the camera's location every frame using the plane's transform. - Godot: Attach a script to your Camera node, get a reference to your Plane, and add this to the
_process()function:extends Camera @onready var plane = $Path/To/Your/Plane # Replace with your plane's node path var camera_offset = Vector3(0, 5, -10) # Adjust as needed func _process(delta): global_position = plane.global_position + camera_offset look_at(plane.global_position) # Optional: Keep camera facing the plane
A quick pro tip: Always update the camera's position after the plane's movement logic runs (like using LateUpdate() in Unity or _process() after physics steps in Godot). This prevents jitter by ensuring the camera uses the plane's final position for the current frame.
内容的提问来源于stack exchange,提问作者CTC_CUS

