Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #43 from evolvedant/fix-menu-clipping-and-station-…
Browse files Browse the repository at this point in the history
…issues

Fixed menu so it draws on top, various fixes/enhancements to stations
  • Loading branch information
CyanLaser authored Jul 16, 2021
2 parents 4006f8a + 9e73adf commit 2107d08
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions CyanEmu/Scripts/CyanEmuPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class CyanEmuPlayerController : MonoBehaviour
private enum Stance {
STANDING,
CROUCHING,
PRONE
PRONE,
SITTING
}

public const float DEFAULT_RUN_SPEED_ = 4;
Expand All @@ -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;
Expand Down Expand Up @@ -90,6 +92,7 @@ private enum Stance {
private CollisionFlags collisionFlags_;
private bool peviouslyGrounded_;
private bool legacyLocomotion_;
private bool updatePosition_;

private Texture2D reticleTexture_;

Expand Down Expand Up @@ -150,6 +153,7 @@ private void Awake()
cameraHolder.transform.SetParent(playerCamera_.transform, false);
camera_ = cameraHolder.AddComponent<Camera>();
camera_.cullingMask &= ~(1 << 18); // remove mirror reflection
updatePosition_ = false;

// TODO, make based on avatar armspan/settings
cameraHolder.transform.localScale = Vector3.one * AVATAR_SCALE_;
Expand Down Expand Up @@ -290,7 +294,7 @@ private void CreateMenu()
menu_.layer = menuLayer;
menu_.transform.parent = transform.parent;
Canvas canvas = menu_.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.worldCamera = camera_;
canvas.planeDistance = camera_.nearClipPlane + 0.1f;
canvas.sortingOrder = 1000;
Expand Down Expand Up @@ -504,15 +508,17 @@ public void EnterStation(CyanEmuStationHelper station)
currentStation_.ExitStation();
}

currentStation_ = station;

if (!station.IsMobile)
{
characterController_.enabled = false;
Teleport(station.EnterLocation, false);
mouseLook_.SetBaseRotation(station.EnterLocation);
mouseLook_.SetRotation(Quaternion.identity);
}

currentStation_ = station;
stance_ = Stance.SITTING;
updatePosition_ = true;
}

public void ExitStation(CyanEmuStationHelper station)
Expand All @@ -526,6 +532,8 @@ public void ExitStation(CyanEmuStationHelper station)
}
mouseLook_.SetBaseRotation(null);
jump_ = false;
stance_ = Stance.STANDING;
updatePosition_ = true;
}

public void PickupObject(CyanEmuPickupHelper pickup)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 2107d08

Please sign in to comment.