diff --git a/Assets/Scenes/PlayerControllerTest.shade b/Assets/Scenes/PlayerControllerTest.shade index 203bbfeb..7a30019f 100644 --- a/Assets/Scenes/PlayerControllerTest.shade +++ b/Assets/Scenes/PlayerControllerTest.shade @@ -69,8 +69,8 @@ NumberOfChildren: 3 Components: Transform Component: - Translate: {x: -21.4454765, y: -3.67383885, z: -3.43293667} - Rotate: {x: -0, y: 0, z: 0} + Translate: {x: 0.214953125, y: -3.67369676, z: -3.03063416} + Rotate: {x: -0, y: 0, z: -0} Scale: {x: 2, y: 2, z: 2} IsActive: true Renderable Component: @@ -83,7 +83,7 @@ Drag: 2 Angular Drag: 0 Use Gravity: false - Interpolate: false + Interpolate: true Sleeping Enabled: true Freeze Position X: false Freeze Position Y: false @@ -108,7 +108,7 @@ maxMoveVel: 4 moveForce: 50 sprintMultiplier: 1.5 - rotationFactorPerFrame: 1 + rotationFactorPerFrame: 4 maxJumpHeight: 4 maxJumpTime: 0.75 fallMultipler: 2 @@ -116,7 +116,9 @@ mediumMultiper: 0.5 heavyMultiper: 0.25 - Type: PickAndThrow - throwForce: [200, 300, 200] + throwForce: [300, 300, 300] + delayTimer: 1 + aimingLength: 1.5 - EID: 3 Name: HoldingPoint IsActive: true @@ -135,13 +137,13 @@ Components: Transform Component: Translate: {x: 0, y: 0, z: 0} - Rotate: {x: -0.607372105, y: 4.78226185, z: 0} + Rotate: {x: -0.361278683, y: 4.97423792, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true Camera Component: - Position: {x: -21.4454765, y: -3.67383885, z: -3.43293667} - Pitch: -34.7998581 - Yaw: 274.003418 + Position: {x: 0.214953125, y: -3.67369676, z: -3.03063416} + Pitch: -20.6997433 + Yaw: 285.002838 Roll: 0 Width: 1920 Height: 1080 @@ -287,8 +289,8 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 3.19867921, y: -3.66373587, z: -4.99996376} - Rotate: {x: -9.79829474e-06, y: 1.93362598e-06, z: 2.07606699e-05} + Translate: {x: 3.19865847, y: -3.66369891, z: -4.99997044} + Rotate: {x: -1.62010674e-05, y: 2.19047888e-06, z: 6.4769687e-05} Scale: {x: 2, y: 2, z: 2} IsActive: true Renderable Component: @@ -298,10 +300,10 @@ RigidBody Component: Type: Dynamic Mass: 1 - Drag: 0 - Angular Drag: 0 + Drag: 0.100000001 + Angular Drag: 0.100000001 Use Gravity: true - Interpolate: false + Interpolate: true Sleeping Enabled: true Freeze Position X: false Freeze Position Y: false @@ -337,9 +339,9 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: -21.4424801, y: -1.21456838, z: -1.82083583} - Rotate: {x: -0, y: 0, z: -0} - Scale: {x: 2, y: 2, z: 2} + Translate: {x: -5.02078199, y: -1.27369666, z: -2.14885736} + Rotate: {x: -9.82871934e-05, y: 0.000654734089, z: -3.21757163e-08} + Scale: {x: 1.99998975, y: 2, z: 1.99998975} IsActive: true Renderable Component: Mesh: 144838771 @@ -348,10 +350,10 @@ RigidBody Component: Type: Dynamic Mass: 1 - Drag: 5 - Angular Drag: 1 + Drag: 0.100000001 + Angular Drag: 0.100000001 Use Gravity: true - Interpolate: false + Interpolate: true Sleeping Enabled: true Freeze Position X: false Freeze Position Y: false diff --git a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs index 1ffeaef7..7342a126 100644 --- a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs +++ b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs @@ -1,4 +1,5 @@ using SHADE; +using SHADE_Scripting; using System; using static PlayerController; @@ -6,24 +7,47 @@ public class PickAndThrow : Script { public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f); public GameObject item { get; set; } + public float delayTimer = 1.0f; + public float aimingLength = 1.5f; + + private float timer; private PlayerController pc; private Camera cam; private Transform itemTransform; private RigidBody itemRidibody; private Transform raccoonHoldLocation; + private Transform playerTran; + private ThirdPersonCamera tpc; private float lastXDir; private float lastZDir; private bool inRange = false; + protected override void awake() { + playerTran = GetComponent(); + if (playerTran) + Debug.Log("PLAYERTRANSFORM EMPTY"); ; + pc = GetScript(); + if(!pc) + Debug.Log("PLAYER CONTROLLER EMPTY"); + raccoonHoldLocation = GetComponentInChildren(); if (raccoonHoldLocation == null) Debug.Log("CHILD EMPTY"); + + tpc = GetScriptInChildren(); + if(!tpc) + Debug.Log("TPC EMPTY"); + + timer = delayTimer; } protected override void update() { + if(timer <= delayTimer) + timer += Time.DeltaTimeF; + CalculateDir(); if (pc && itemRidibody && itemTransform) @@ -31,15 +55,27 @@ public class PickAndThrow : Script if (pc.holdItem) { itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition; + itemTransform.LocalRotation = playerTran.LocalRotation; if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) { + Debug.Log("AIMING"); + pc.isAiming = true; + pc.camArm.ArmLength = aimingLength; + } + + if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming) + { + pc.isAiming = false; + if(tpc) + pc.camArm.ArmLength = tpc.armLength; pc.holdItem = false; inRange = false; itemRidibody.IsGravityEnabled = true; itemRidibody.AddForce(new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir)); itemRidibody.LinearVelocity += pc.rb.LinearVelocity; ResetItemObject(); + timer = 0.0f; } if (Input.GetMouseButtonDown(Input.MouseCode.RightButton)) @@ -54,10 +90,14 @@ public class PickAndThrow : Script itemRidibody.IsGravityEnabled = true; } - if (pc && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) + if (timer > delayTimer && pc && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) { - pc.holdItem = true; - RetrieveItemComponets(); + if (pc.currentState == RaccoonStates.WALKING || pc.currentState == RaccoonStates.IDLE) + { + Debug.Log("PCIKUP"); + pc.holdItem = true; + RetrieveItemComponets(); + } } } @@ -108,12 +148,17 @@ public class PickAndThrow : Script } } + private void DelayCheck() + { + timer += Time.DeltaTimeF; + } + protected override void onCollisionEnter(CollisionInfo info) { } protected override void onTriggerEnter(CollisionInfo info) { - if (info.GameObject.GetScript() != null && !pc.holdItem) + if (info.GameObject.GetScript() && !pc.holdItem) { item = info.GameObject; inRange = true; diff --git a/Assets/Scripts/Gameplay/Player/SC_PlayerController.cs b/Assets/Scripts/Gameplay/Player/SC_PlayerController.cs index 5afbc18f..27e18659 100644 --- a/Assets/Scripts/Gameplay/Player/SC_PlayerController.cs +++ b/Assets/Scripts/Gameplay/Player/SC_PlayerController.cs @@ -29,10 +29,12 @@ public class PlayerController : Script public RigidBody rb { get; set; } private Transform tranform; private Camera cam; + public CameraArm camArm { get; set; } private PickAndThrow pat; private StateMachine stateMachine; public bool holdItem { get; set; } + public bool isAiming { get; set; } [Tooltip("The current state fo the raccoon")] public RaccoonStates currentState = RaccoonStates.IDLE; @@ -48,25 +50,19 @@ public class PlayerController : Script private float oldForce; private float maxOldVel; private bool sprintIncreaseOnce = false; - - public float xAxisMove { get; set; } - public float zAxisMove { get; set; } public Vector2 axisMove { get; set; } public bool isMoveKeyPress { get; set; } - [Tooltip("curr not working")] + [Tooltip("How fast player will turn")] public float rotationFactorPerFrame = 1.0f; //Jumping vars================================================================== - [SerializeField] [Tooltip("max height of the jump")] public float maxJumpHeight = 4.0f; - [SerializeField] [Tooltip("max amt of time it will take for the jump")] public float maxJumpTime = 0.75f; - [SerializeField] [Tooltip("increase gravity when falling")] public float fallMultipler = 2.0f; private float initialJumpVel; @@ -75,8 +71,11 @@ public class PlayerController : Script private float groundGravity = -0.5f; //ItemMultipler================================================================== + [Tooltip("How light item will affect player jump")] public float lightMultiper = 0.75f; + [Tooltip("How medium item will affect player jump")] public float mediumMultiper = 0.5f; + [Tooltip("How heavy item will affect player jump")] public float heavyMultiper = 0.25f; protected override void awake() @@ -84,6 +83,7 @@ public class PlayerController : Script //default setup isMoveKeyPress = false; holdItem = false; + isAiming = false; //Jump setup float timeToApex = maxJumpTime / 2; @@ -94,11 +94,6 @@ public class PlayerController : Script rb = GetComponent(); if (rb == null) Debug.LogError("RigidBody is NULL!"); - else - { - rb.IsGravityEnabled = false; - rb.Interpolating = false; - } //Transform check tranform = GetComponent(); @@ -125,9 +120,12 @@ public class PlayerController : Script protected override void update() { - if (cam == null) + if (!cam) cam = GetComponentInChildren(); + if(!camArm) + camArm = GetComponentInChildren(); + Rotation(); GotCaught(); //Debug.Log($"{currentState}"); //Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}"); @@ -137,9 +135,6 @@ public class PlayerController : Script protected override void fixedUpdate() { - //Rotation(); - - MoveKey(); Move(); Sprint(); @@ -210,20 +205,16 @@ public class PlayerController : Script { rb.LinearVelocity += new Vector3(axisMove.x * moveForce, 0.0f, axisMove.y * moveForce) * Time.DeltaTimeF; - if (isMoveKeyPress) + if (isMoveKeyPress && rb) { - if (rb) + Vector3 velNor = rb.LinearVelocity; + velNor.y = 0.0f; + if (velNor.GetMagnitude() > maxMoveVel) { - Vector3 velNor = rb.LinearVelocity; - velNor.y = 0.0f; - if (velNor.GetMagnitude() > maxMoveVel) - { - velNor.Normalise(); - velNor *= maxMoveVel; - rb.LinearVelocity = new Vector3(velNor.x, rb.LinearVelocity.y, velNor.z); - } + velNor.Normalise(); + velNor *= maxMoveVel; + rb.LinearVelocity = new Vector3(velNor.x, rb.LinearVelocity.y, velNor.z); } - } } } @@ -293,19 +284,17 @@ public class PlayerController : Script private void Rotation() { - Vector3 poitionToLookAt; - poitionToLookAt.x = axisMove.x; - poitionToLookAt.y = 0.0f; - poitionToLookAt.z = axisMove.y; - - if (tranform != null) + if (isMoveKeyPress && tranform && !isAiming) { Quaternion currentRotation = tranform.LocalRotation; - if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING) - { - Quaternion targetRotation = Quaternion.LookRotation(poitionToLookAt, new Vector3(0.0f, 1.0f, 0.0f)); - tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.DeltaTime); - } + Quaternion targetRotation = Quaternion.LookRotation(new Vector3(axisMove.x, 0.0f, axisMove.y), new Vector3(0.0f, 1.0f, 0.0f)); + tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.DeltaTime); + } + else if (camArm && tranform && isAiming) + { + Quaternion currentRotation = tranform.LocalRotation; + Quaternion targetRotation = Quaternion.Euler(0.0f, SHADE.Math.DegreesToRadians(camArm.Yaw + 180.0f), 0.0f); + tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.DeltaTime); } } diff --git a/Assets/Scripts/Gameplay/Player/ThirdPersonCamera.cs b/Assets/Scripts/Gameplay/Player/ThirdPersonCamera.cs index fed26ae9..dc374125 100644 --- a/Assets/Scripts/Gameplay/Player/ThirdPersonCamera.cs +++ b/Assets/Scripts/Gameplay/Player/ThirdPersonCamera.cs @@ -8,53 +8,49 @@ using SHADE; namespace SHADE_Scripting { - public class ThirdPersonCamera: Script + public class ThirdPersonCamera : Script + { + + public float armLength = 2.0f; + public float turnSpeedPitch = 0.3f; + public float turnSpeedYaw = 0.5f; + public float pitchClamp = 45.0f; + + protected override void awake() { + AddComponent(); - public float armLength = 2.0f; - public float turnSpeedPitch = 0.3f; - public float turnSpeedYaw = 0.5f; - public float pitchClamp = 45.0f; - - protected override void awake() - { - AddComponent(); - - if(!GetComponent()) - { - AddComponent(); - } - GetComponent().SetMainCamera(); - if (!GetComponent()) - { - AddComponent(); - } - GetComponent().ArmLength = armLength; - } + if (!GetComponent()) + { + AddComponent(); + } + GetComponent().SetMainCamera(); + if (!GetComponent()) + { + AddComponent(); + } + GetComponent().ArmLength = armLength; + } protected override void update() { - if (Input.GetMouseButton(Input.MouseCode.RightButton)) + CameraArm arm = GetComponent(); + if (arm) { - CameraArm arm = GetComponent(); - if (arm) - { - Vector2 vel = Input.GetMouseVelocity(); - arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF; - arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF; + Vector2 vel = Input.GetMouseVelocity(); + arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF; + arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF; - if (arm.Pitch > pitchClamp) - { - arm.Pitch = pitchClamp; - } - else if (arm.Pitch < 0) - { - arm.Pitch = 0; - } - - } + if (arm.Pitch > pitchClamp) + { + arm.Pitch = pitchClamp; + } + else if (arm.Pitch < 0) + { + arm.Pitch = 0; } } - } + + } } diff --git a/Assets/Scripts/Gameplay/Player/UT_PlayerCaughtState .cs.shmeta b/Assets/Scripts/Gameplay/Player/UT_PlayerCaughtState .cs.shmeta index 6a7b9648..afe53e39 100644 --- a/Assets/Scripts/Gameplay/Player/UT_PlayerCaughtState .cs.shmeta +++ b/Assets/Scripts/Gameplay/Player/UT_PlayerCaughtState .cs.shmeta @@ -1,3 +1,3 @@ Name: UT_PlayerCaughtState -ID: 152856879 +ID: 153166405 Type: 9 diff --git a/Assets/Scripts/Gameplay/SC_Item.cs b/Assets/Scripts/Gameplay/SC_Item.cs index e6cc79af..56ee0d0e 100644 --- a/Assets/Scripts/Gameplay/SC_Item.cs +++ b/Assets/Scripts/Gameplay/SC_Item.cs @@ -13,9 +13,15 @@ public class Item : Script public ItemCategory currCategory; private RigidBody rb; + private Collider collider; protected override void awake() { + collider = GetComponent(); + if (collider) + { + collider.GetCollisionShape(0).Density = 1; + } rb = GetComponent(); if (rb) {