Hi,
I have implemented a camera reset function that works as expected under normal conditions. However, when the pan feature is used, the reset functionality does not behave as intended. I’ve attached a video for reference.
video: Game creator Ks's Video - Jan 28, 2025
It seems like you’re having trouble with the camera reset function after using the pan feature. The issue may arise from the fact that the setBaseCameraPosition method is not considering the current state of the camera after panning.
Let’s break down a possible solution:
Ensure that when the reset function is called, it resets both the camera’s position and orientation based on its original state before any panning occurred.
Capture the original position and rotation of the camera before any pan actions take place to be able to reset to those values effectively.
Here’s a revised version of your setBaseCameraPosition function accounting for both position and rotation resets:
setBaseCameraPosition(cam: Camera) {
if (!this.baseCamera) return;
const originalPosition = new Vector3(0, cam.worldPosition.y, cam.worldPosition.z); // Original position without pan
const originalRotation = new Vector3(cam.worldRotation.x, cam.worldRotation.y, cam.worldRotation.z); // Original rotation
// Set base camera position and rotation
this.baseCamera.setWorldPosition(originalPosition);
this.baseCamera.setWorldRotation(originalRotation);
const baseCamOrbitControl = GameObject.getComponent(this.baseCamera.gameObject, OrbitControls);
if (baseCamOrbitControl) {
baseCamOrbitControl.setCameraTargetPosition(cam.gameObject, 1);
}
}
With this adjustment, the camera should reset to its intended position and rotation, regardless of the pan state. Make sure to check for any console logs or errors that may indicate the state of your orbit controls or camera at the time of reset.
If you need more assistance, please provide additional context on how the pan functionality is implemented and any specific behaviors you expect during the reset.
For more references, you can check the appropriate APIs and functionalities in the documentation linked below:
Yes both - one sets the camera position and once where the camera looks at. There’s also a call to set both at the same time which takes a object3D for the position and forward direction.