Skip to content

Add third-person camera.#786

Open
s-ilent wants to merge 11 commits intoBasisVR:developerfrom
s-ilent:3p-camera
Open

Add third-person camera.#786
s-ilent wants to merge 11 commits intoBasisVR:developerfrom
s-ilent:3p-camera

Conversation

@s-ilent
Copy link
Copy Markdown
Contributor

@s-ilent s-ilent commented Apr 28, 2026

This is a basic third person camera added to the BasisLocalCameraDriver.

When third-person is enabled, the camera follows the player and collides with world geometry on specified layers. I also added some InputActions to handle switching between first/third person state, and zooming the camera in and out. Zooming will affect the camera distance and the FOV. The camera distance is also affected by the local player scale.

The camera is updated on AfterSimulateOnLate to allow it to act as though it were detached from the player.

The code probably needs some cleanup before it can be integrated.

Issues and Todos:

  • Missing runtime settings menu to configure the camera parameters.
  • The call to ScaleheadToZero is skipped when in third-person mode. However, the head disappears when a mirror is on-screen.
  • SetupCollisionMask overrides the CameraCollisionMask and it probably shouldn't.
  • I haven't tested with avatars which are really small or really large before scaling.

Copy link
Copy Markdown
Collaborator

@dooly123 dooly123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update to the latest developer

/// </summary>
private void SimulateThirdPerson()
{
if (!BasisDeviceManagement.IsUserInDesktop() || CameraInstance == null)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CameraInstance will never be null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, I wasn't sure

{
if (!_wasThirdPerson) return;

transform.localPosition = Vector3.zero;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform.setlocalpositionandrotation instead

private void UpdateThirdPersonTargets(Transform parentTransform, float scale, float dt)
{
Vector3 targetTrackingPos = parentTransform.position;
float targetPitch = parentTransform.rotation.eulerAngles.x;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rotation. Euler converts it into a Euler (math), we then do that 2x

Transform parentTransform = transform.parent;
if (parentTransform == null) return;

float dt = Time.deltaTime;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be parsing down the delta time from BasisEventDriver

}

transform.position = desiredWorldPos;
transform.rotation = desiredRotation;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetPositionAndRotation

private void ApplyThirdPersonTransform(float scale)
{
float zoomT = Mathf.InverseLerp(ThirdPersonMinZoom * scale, ThirdPersonMaxZoom * scale, _currentCamParams.distance);
CameraInstance.fieldOfView = Mathf.Lerp(ThirdPersonMinFoV, ThirdPersonMaxFoV, zoomT);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this overrides users fov control are we sure we want todo this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Third-person FOV should be seperate from first-person FOV, I'll make it configurable with the other camera settings.

@dooly123
Copy link
Copy Markdown
Collaborator

thx for putting in the time for this we need todo a bunch more before its reliable, we also need to solve the distance for the reduction system being wrong hmm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants