diff --git a/CyanEmu/Scripts/CyanEmuPlayerController.cs b/CyanEmu/Scripts/CyanEmuPlayerController.cs index 57582a4..5bf3947 100644 --- a/CyanEmu/Scripts/CyanEmuPlayerController.cs +++ b/CyanEmu/Scripts/CyanEmuPlayerController.cs @@ -27,7 +27,8 @@ public class CyanEmuPlayerController : MonoBehaviour private enum Stance { STANDING, CROUCHING, - PRONE + PRONE, + SITTING } public const float DEFAULT_RUN_SPEED_ = 4; @@ -39,6 +40,7 @@ private enum Stance { private const float STANDING_HEIGHT_ = 1.6f; private const float CROUCHING_HEIGHT_ = 1.0f; private const float PRONE_HEIGHT_ = 0.5f; + private const float SITTING_HEIGHT_ = 0.88f; private const float STICK_TO_GROUND_FORCE_ = 2f; private const float RATE_OF_AIR_ACCELERATION_ = 5f; @@ -90,6 +92,7 @@ private enum Stance { private CollisionFlags collisionFlags_; private bool peviouslyGrounded_; private bool legacyLocomotion_; + private bool updatePosition_; private Texture2D reticleTexture_; @@ -150,6 +153,7 @@ private void Awake() cameraHolder.transform.SetParent(playerCamera_.transform, false); camera_ = cameraHolder.AddComponent(); camera_.cullingMask &= ~(1 << 18); // remove mirror reflection + updatePosition_ = false; // TODO, make based on avatar armspan/settings cameraHolder.transform.localScale = Vector3.one * AVATAR_SCALE_; @@ -290,7 +294,7 @@ private void CreateMenu() menu_.layer = menuLayer; menu_.transform.parent = transform.parent; Canvas canvas = menu_.AddComponent(); - canvas.renderMode = RenderMode.ScreenSpaceCamera; + canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvas.worldCamera = camera_; canvas.planeDistance = camera_.nearClipPlane + 0.1f; canvas.sortingOrder = 1000; @@ -504,8 +508,6 @@ public void EnterStation(CyanEmuStationHelper station) currentStation_.ExitStation(); } - currentStation_ = station; - if (!station.IsMobile) { characterController_.enabled = false; @@ -513,6 +515,10 @@ public void EnterStation(CyanEmuStationHelper station) mouseLook_.SetBaseRotation(station.EnterLocation); mouseLook_.SetRotation(Quaternion.identity); } + + currentStation_ = station; + stance_ = Stance.SITTING; + updatePosition_ = true; } public void ExitStation(CyanEmuStationHelper station) @@ -526,6 +532,8 @@ public void ExitStation(CyanEmuStationHelper station) } mouseLook_.SetBaseRotation(null); jump_ = false; + stance_ = Stance.STANDING; + updatePosition_ = true; } public void PickupObject(CyanEmuPickupHelper pickup) @@ -852,7 +860,7 @@ private void UpdateStance() { bool updatePosition = false; - if (Input.GetKeyDown(CyanEmuSettings.Instance.crouchKey)) + if (Input.GetKeyDown(CyanEmuSettings.Instance.crouchKey) && currentStation_ == null) { updatePosition = true; if (stance_ == Stance.CROUCHING) @@ -864,7 +872,7 @@ private void UpdateStance() stance_ = Stance.CROUCHING; } } - if (Input.GetKeyDown(CyanEmuSettings.Instance.proneKey)) + if (Input.GetKeyDown(CyanEmuSettings.Instance.proneKey) && currentStation_ == null) { updatePosition = true; if (stance_ == Stance.PRONE) @@ -881,9 +889,11 @@ private void UpdateStance() if (updatePosition) { Vector3 cameraPosition = playerCamera_.transform.localPosition; - cameraPosition.y = (stance_ == Stance.STANDING ? STANDING_HEIGHT_ : stance_ == Stance.CROUCHING ? CROUCHING_HEIGHT_ : PRONE_HEIGHT_); + cameraPosition.y = (stance_ == Stance.STANDING ? STANDING_HEIGHT_ : stance_ == Stance.CROUCHING ? CROUCHING_HEIGHT_ : stance_ == Stance.PRONE ? PRONE_HEIGHT_ : SITTING_HEIGHT_); playerCamera_.transform.localPosition = cameraPosition; } + + updatePosition_ = false; } private void GetInput(out Vector2 speed, out Vector2 input)