Skip to content

Commit

Permalink
Camera bug fix
Browse files Browse the repository at this point in the history
Potentially fixed weird bug where camera moves behind player
  • Loading branch information
amripara committed Mar 1, 2022
1 parent 4641f7d commit 3be1e5a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
33 changes: 33 additions & 0 deletions Assets/Scenes/Amri/Level 1 - ProBuilder.unity
Original file line number Diff line number Diff line change
Expand Up @@ -66747,6 +66747,11 @@ MonoBehaviour:
m_SelectedFaces:
m_SelectedEdges: []
m_SelectedVertices:
--- !u!1 &1154372000 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 156714141933758697, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
m_PrefabInstance: {fileID: 156714142599601327}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1161637326
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -115742,6 +115747,30 @@ PrefabInstance:
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 156714141933758696, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 156714141933758696, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 156714141933758696, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 156714141933758696, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 156714141933758696, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 156714141933758696, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 156714141933758719, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: near clip plane
value: 0.01
Expand Down Expand Up @@ -115790,6 +115819,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 156714143368168781, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: playerCam
value:
objectReference: {fileID: 1154372000}
- target: {fileID: 156714143368168781, guid: 04d562709c8c70f479dfcaaae77b0b1d, type: 3}
propertyPath: movementSpeed
value: 10
Expand Down
21 changes: 14 additions & 7 deletions Assets/Scripts/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
public class PlayerController : MonoBehaviour
{
public PlayerInput playerInput;
[SerializeField] GameObject playerCam;
private Vector3 camPos;
private Rigidbody rb;
private CapsuleCollider capsule;

Expand Down Expand Up @@ -107,6 +109,7 @@ private void Awake()
// Start is called before the first frame update
void Start()
{
camPos = playerCam.transform.localPosition;
rb = GetComponent<Rigidbody>();
capsule = GetComponent<CapsuleCollider>();
count = 0;
Expand All @@ -117,6 +120,7 @@ void Start()
// Update is called once per frame
void Update()
{
playerCam.transform.localPosition = camPos;
HandleInput();
#region Time Slow
if (!TimeSlowIsActive)
Expand Down Expand Up @@ -166,13 +170,17 @@ private void HandleInput()
rb.AddForce(Vector3.up * 5, ForceMode.VelocityChange);
}
isGrounded = false;
}
if (playerInput.actions["Jump"].WasReleasedThisFrame())
{

}
if (transform.position.y < 0) // NOTE: should be modified later to add more potential death scenarios
{
// loseTextObject.SetActive(true);
KillPlayer();
}
if (playerInput.actions["Slide"].WasPerformedThisFrame() && isGrounded && !isSliding)
if (playerInput.actions["Slide"].WasPerformedThisFrame() && rb.velocity.y <= 0 && !isSliding)
{
isSliding = true;
stopSlide = false;
Expand Down Expand Up @@ -206,6 +214,11 @@ private void HandleInput()
if (playerInput.actions["TimeSlow"].WasReleasedThisFrame()) {
TimeSlowIsActive = false;
}
//Camera movement
//Debug.Log(playerInput.actions["Look"].ReadValue<Vector2>());
//Vector2 mouseLook = playerInput.actions["Look"].ReadValue<Vector2>();
//playerCam.transform.Rotate(new Vector3(-mouseLook.y, mouseLook.x, 0));

}
else
{
Expand Down Expand Up @@ -306,12 +319,6 @@ private void CheckCount()
}
}

private void UnSlide()
{
//capsule.height = originalHeight;
isSliding = false;
}

public void KillPlayer()
{
deathController.SetActive(true);
Expand Down

0 comments on commit 3be1e5a

Please sign in to comment.