Skip to content

Commit

Permalink
Fixes to eye height calculations in PlayerHeightChanger
Browse files Browse the repository at this point in the history
Found multiple problems with eye/camera height adjustments:
-Eye height was not factored into target camera levels at startup except for riding. This would result in player eye level landing at wrong position after crouching/standing.
-Camera was outside capsule when crouching.
-Player's prefab eye starting height was slightly misaligned compared to runtime adjustments.
-ControllerHeightChange had a workaround for eye height when dismounting/mounting because this wasn't have already factored in.
Fixed all the above by aligning prefab camera starting position and setting eye height in target camera positions in startup. This also means the workaround for riding in ControllerHeightChange can be removed as standing target height now correctly set.
Tested crouch/stand, mount/dismount, swim/walk, and combinations with save/load and camera now returning to correct starting position.
  • Loading branch information
Interkarma committed Dec 16, 2022
1 parent d1d7cbc commit 0d24d3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
9 changes: 5 additions & 4 deletions Assets/Prefabs/Player/PlayerAdvanced.prefab
Expand Up @@ -717,7 +717,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100002}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.8, z: 0}
m_LocalPosition: {x: 0, y: 0.9, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4832112164805246}
Expand Down Expand Up @@ -798,11 +798,9 @@ MonoBehaviour:
invertMouseY: 0
lockCursor: 1
sensitivity: {x: 1, y: 1}
smoothing: {x: 3, y: 3}
sensitivityScale: 1
joystickSensitivityScale: 1
enableMouseLook: 1
enableSmoothing: 0
simpleCursorLock: 0
characterBody: {fileID: 100000}
--- !u!114 &114619655177981728
Expand Down Expand Up @@ -855,6 +853,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
isRetroPresenter: 0
retroClearerCamera: {fileID: 0}
--- !u!114 &1573166380
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -913,7 +912,9 @@ MonoBehaviour:
m_ShowCustomSorter: 0
breakBeforeColorGrading: 0
m_BeforeTransparentBundles: []
m_BeforeStackBundles: []
m_BeforeStackBundles:
- assemblyQualifiedName: ColorBoost, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null
m_AfterStackBundles: []
--- !u!1 &100004
GameObject:
Expand Down
18 changes: 5 additions & 13 deletions Assets/Scripts/Game/Player/PlayerHeightChanger.cs
Expand Up @@ -107,9 +107,9 @@ private void Start()
mainCamera = GameManager.Instance.MainCamera;
levitateMotor = GetComponent<LevitateMotor>();
climbingMotor = GetComponent<ClimbingMotor>();
camSwimLevel = controllerSwimHeight / 2f;
camCrouchLevel = controllerCrouchHeight / 2f;
camStandLevel = controllerStandingHeight / 2f;
camSwimLevel = controllerSwimHeight / 2f - eyeHeight;
camCrouchLevel = controllerCrouchHeight / 2f - eyeHeight;
camStandLevel = controllerStandingHeight / 2f - eyeHeight;
camRideLevel = controllerRideHeight / 2f - eyeHeight;
//camSwimToCrouchDist = (controllerCrouchHeight - controllerSwimHeight) / 2f;
camCrouchToStandDist = (controllerStandingHeight - controllerCrouchHeight) / 2f;
Expand Down Expand Up @@ -475,17 +475,9 @@ private float ControllerHeightChange(float heightChange)
bool dismounting = (heightAction == HeightChangeAction.DoDismounting);
bool mounting = (heightAction == HeightChangeAction.DoMounting);
controller.height = GetNearbyFloat(controller.height + heightChange);
float eyeChange = 0;
if (GameManager.Instance.PlayerMotor.OnExteriorWater != PlayerMotor.OnExteriorWaterMethod.Swimming)
{
if (dismounting)
eyeChange = -1 * eyeHeight;
else if (mounting)
eyeChange = eyeHeight;
}
controller.transform.position += new Vector3(0, heightChange / 2 + eyeChange);
controller.transform.position += new Vector3(0, heightChange / 2f);

return controller.height / 2 + eyeChange;
return controller.height / 2f;
}

/// <summary>
Expand Down

0 comments on commit 0d24d3e

Please sign in to comment.