From 122bf23b3039e731839c021e7238fb1e17dc0345 Mon Sep 17 00:00:00 2001 From: Melbyj1125 <60886701+Melbyj1125@users.noreply.github.com> Date: Mon, 11 Oct 2021 12:12:57 -0500 Subject: [PATCH] Fixed Player Jump and Added Itemmanager PlayerJump uses raycast to detect when to get jumps back ItemManager Holds all scriptable Objects that are within resources Added a resource folder --- Assets/Scenes/Demos/MovementScene.unity | 23 +++++++-- .../ItemScripts/InventoryManager.cs | 12 ++++- .../PlayerScripts/ItemScripts/Resources.meta | 8 +++ .../{ => Resources}/ItemObjects.meta | 0 .../ItemObjects/QuickStandup.asset | 0 .../ItemObjects/QuickStandup.asset.meta | 0 .../ItemObjects/RollerSkates.asset | 0 .../ItemObjects/RollerSkates.asset.meta | 0 .../{ => Resources}/ItemObjects/Springs.asset | 0 .../ItemObjects/Springs.asset.meta | 0 .../ItemObjects/StrongerKick.asset | 0 .../ItemObjects/StrongerKick.asset.meta | 0 .../ItemObjects/TripleJump.asset | 0 .../ItemObjects/TripleJump.asset.meta | 0 .../Scripts/PlayerScripts/PlayerInventory.cs | 11 ++++ .../Scripts/PlayerScripts/PlayerMovement.cs | 51 +++++++++++-------- Assets/Scripts/PlayerScripts/PlayerStats.cs | 6 +-- ProjectSettings/TagManager.asset | 2 +- 18 files changed, 83 insertions(+), 30 deletions(-) create mode 100644 Assets/Scripts/PlayerScripts/ItemScripts/Resources.meta rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects.meta (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/QuickStandup.asset (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/QuickStandup.asset.meta (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/RollerSkates.asset (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/RollerSkates.asset.meta (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/Springs.asset (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/Springs.asset.meta (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/StrongerKick.asset (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/StrongerKick.asset.meta (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/TripleJump.asset (100%) rename Assets/Scripts/PlayerScripts/ItemScripts/{ => Resources}/ItemObjects/TripleJump.asset.meta (100%) diff --git a/Assets/Scenes/Demos/MovementScene.unity b/Assets/Scenes/Demos/MovementScene.unity index 19a95f2..69b7d28 100644 --- a/Assets/Scenes/Demos/MovementScene.unity +++ b/Assets/Scenes/Demos/MovementScene.unity @@ -329,9 +329,10 @@ GameObject: - component: {fileID: 296575269} - component: {fileID: 296575271} - component: {fileID: 296575272} - m_Layer: 0 + - component: {fileID: 296575273} + m_Layer: 3 m_Name: Player - m_TagString: Untagged + m_TagString: Player m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -472,9 +473,21 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5a5d879591af1084ab5d3a35fcd53086, type: 3} m_Name: m_EditorClassIdentifier: - items: - - {fileID: 11400000, guid: ca4d5584eacf416478beba5cd283bfa3, type: 2} + items: [] pStats: {fileID: 0} +--- !u!114 &296575273 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 296575264} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 66519fc5420181e45850c591aa1179ec, type: 3} + m_Name: + m_EditorClassIdentifier: + allItems: [] --- !u!1 &478416584 GameObject: m_ObjectHideFlags: 0 @@ -1189,7 +1202,7 @@ GameObject: - component: {fileID: 1710897360} - component: {fileID: 1710897359} - component: {fileID: 1710897358} - m_Layer: 0 + m_Layer: 3 m_Name: Main Camera m_TagString: MainCamera m_Icon: {fileID: 0} diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/InventoryManager.cs b/Assets/Scripts/PlayerScripts/ItemScripts/InventoryManager.cs index 737815d..5e153e9 100644 --- a/Assets/Scripts/PlayerScripts/ItemScripts/InventoryManager.cs +++ b/Assets/Scripts/PlayerScripts/ItemScripts/InventoryManager.cs @@ -4,5 +4,15 @@ using UnityEngine; public class InventoryManager : MonoBehaviour { - + public Item[] allItems; + private List itemList; + public List ItemList{ + get{ return itemList; } + set{ itemList = value; } + } + void Awake(){ + allItems = Resources.LoadAll("ItemObjects"); + + itemList = new List(allItems); + } } diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/Resources.meta b/Assets/Scripts/PlayerScripts/ItemScripts/Resources.meta new file mode 100644 index 0000000..0c3df52 --- /dev/null +++ b/Assets/Scripts/PlayerScripts/ItemScripts/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3f81b99cf16b831458726bf10a114803 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects.meta b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects.meta similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects.meta rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects.meta diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/QuickStandup.asset b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/QuickStandup.asset similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/QuickStandup.asset rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/QuickStandup.asset diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/QuickStandup.asset.meta b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/QuickStandup.asset.meta similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/QuickStandup.asset.meta rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/QuickStandup.asset.meta diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/RollerSkates.asset b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/RollerSkates.asset similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/RollerSkates.asset rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/RollerSkates.asset diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/RollerSkates.asset.meta b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/RollerSkates.asset.meta similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/RollerSkates.asset.meta rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/RollerSkates.asset.meta diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/Springs.asset b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/Springs.asset similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/Springs.asset rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/Springs.asset diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/Springs.asset.meta b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/Springs.asset.meta similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/Springs.asset.meta rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/Springs.asset.meta diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/StrongerKick.asset b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/StrongerKick.asset similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/StrongerKick.asset rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/StrongerKick.asset diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/StrongerKick.asset.meta b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/StrongerKick.asset.meta similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/StrongerKick.asset.meta rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/StrongerKick.asset.meta diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/TripleJump.asset b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/TripleJump.asset similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/TripleJump.asset rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/TripleJump.asset diff --git a/Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/TripleJump.asset.meta b/Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/TripleJump.asset.meta similarity index 100% rename from Assets/Scripts/PlayerScripts/ItemScripts/ItemObjects/TripleJump.asset.meta rename to Assets/Scripts/PlayerScripts/ItemScripts/Resources/ItemObjects/TripleJump.asset.meta diff --git a/Assets/Scripts/PlayerScripts/PlayerInventory.cs b/Assets/Scripts/PlayerScripts/PlayerInventory.cs index 28821dd..4e978a0 100644 --- a/Assets/Scripts/PlayerScripts/PlayerInventory.cs +++ b/Assets/Scripts/PlayerScripts/PlayerInventory.cs @@ -4,8 +4,12 @@ using UnityEngine; public class PlayerInventory : MonoBehaviour { + //List of items [SerializeField] List items; + + //Scripts public PlayerStats pStats; + public InventoryManager invMan; public bool AddItem(Item item){ items.Add(item); @@ -21,7 +25,14 @@ public class PlayerInventory : MonoBehaviour void Awake(){ pStats = GetComponent(); + invMan = GetComponent();//////UPDATE WHEN THIS IS NO LONGER ATTACHED TO THE PLAYER + } + + void Start(){ + AddItem(invMan.ItemList[0]); + AddItem(invMan.ItemList[1]); foreach (Item item in items){ + Debug.Log(item.name); item.Equip(pStats); } } diff --git a/Assets/Scripts/PlayerScripts/PlayerMovement.cs b/Assets/Scripts/PlayerScripts/PlayerMovement.cs index 23e58f5..15f4c67 100644 --- a/Assets/Scripts/PlayerScripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerScripts/PlayerMovement.cs @@ -17,7 +17,6 @@ public class PlayerMovement : MonoBehaviour private Vector3 vel; private Vector3 driftVel; - //Character Moving private CharacterController moveController; @@ -25,15 +24,15 @@ public class PlayerMovement : MonoBehaviour private int curJumpNum; private bool jumpPressed; - //Bump physics - float mass = 5.0F; // defines the character mass - Vector3 impact = Vector3.zero; + //Jump physics + private float mass = 5.0F; // defines the character mass + private Vector3 impact = Vector3.zero; + private float distToGround; - - //Camera Variables + private LayerMask ignoreP; private Vector3 camRotation; - private Transform cam; + private Camera cam; [Range(-45, -15)] public int minAngle = -30; @@ -48,7 +47,6 @@ public class PlayerMovement : MonoBehaviour private Vector3 endPoint; private Vector3 mousePos; private RaycastHit hit; - private Camera Cam; ///// void Awake(){ @@ -56,17 +54,21 @@ public class PlayerMovement : MonoBehaviour moveController = GetComponent(); pStats = GetComponent(); Cursor.lockState = CursorLockMode.Locked; + ignoreP = LayerMask.GetMask("Player"); beam = gameObject.AddComponent(); beam.startWidth = 0.2f; beam.endWidth = 0.2f; //camera transform - cam = Camera.main.transform; - Cam = Camera.main; //RENAME WHEN CLEANING UP BLINK + cam = Camera.main; } + + void Start(){ + distToGround = GetComponent().bounds.extents.y; + } // Update is called once per frame @@ -87,11 +89,10 @@ public class PlayerMovement : MonoBehaviour //Checks if player should respawn Respawn(); Blink(); + } - void Update(){ - if(moveController.isGrounded) curJumpNum = 0; - } + //Reads inputs and moves player private void InputController(){ @@ -113,8 +114,9 @@ public class PlayerMovement : MonoBehaviour Jump(); moveController.Move(driftVel); - } - + } + + //Calculates speed current player needs to be going private float PlayerSpeed(){ @@ -140,6 +142,8 @@ public class PlayerMovement : MonoBehaviour } } + + //Applies impact in a direction with the given force public void AddImpact(Vector3 dir, float force){ dir.Normalize(); @@ -147,10 +151,12 @@ public class PlayerMovement : MonoBehaviour impact += dir.normalized * force / mass; } + + //Jump Function private void Jump(){ //If space is pressed apply an upwards force to the player - if(Input.GetAxis("Jump") != 0 && !jumpPressed && curJumpNum < pStats.JumpNum){ + if(Input.GetAxis("Jump") != 0 && !jumpPressed && curJumpNum+1 < pStats.JumpNum){ AddImpact(transform.up, pStats.JumpPow); curJumpNum++; jumpPressed = true; @@ -159,13 +165,18 @@ public class PlayerMovement : MonoBehaviour //NEEDS TO BE MASSIVELY CHANGE LIKELY USE RAYCAST TO CHECK IF ACTUALLY ON GROUND //CANNOT USE CHARACTERCONTROLLER.ISGROUNDED IT IS UNRELIABLE //If grounded no jumps have been used - if(moveController.isGrounded) curJumpNum = 0; + if(IsGrounded()){ + curJumpNum = 0; + } //If space isn't being pressed then jump is false if(Input.GetAxis("Jump")==0) jumpPressed = false; } - + //Improved IsGrounded + private bool IsGrounded(){ + return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f, ~ignoreP); + } //Camera private void Rotate() @@ -175,7 +186,7 @@ public class PlayerMovement : MonoBehaviour camRotation.x -= Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime; camRotation.x = Mathf.Clamp(camRotation.x, minAngle, maxAngle); - cam.localEulerAngles = camRotation; + cam.transform.localEulerAngles = camRotation; } @@ -200,7 +211,7 @@ public class PlayerMovement : MonoBehaviour // Finding mouse pos in 3D space. mousePos = Input.mousePosition; mousePos.z = 20f; - endPoint = Cam.ScreenToWorldPoint(mousePos); + endPoint = cam.ScreenToWorldPoint(mousePos); // Find direction of beam. Vector3 dir = endPoint - origin; diff --git a/Assets/Scripts/PlayerScripts/PlayerStats.cs b/Assets/Scripts/PlayerScripts/PlayerStats.cs index 5e76784..55fd57f 100644 --- a/Assets/Scripts/PlayerScripts/PlayerStats.cs +++ b/Assets/Scripts/PlayerScripts/PlayerStats.cs @@ -5,7 +5,7 @@ using UnityEngine; public class PlayerStats : MonoBehaviour { //Maximum possible player speed - private float maxVel = 30.0f; + private float maxVel = 25.0f; public float MaxVel{ get{ return maxVel; } set{ maxVel = value; } @@ -26,7 +26,7 @@ public class PlayerStats : MonoBehaviour } //Player Jump power - private float acc = 0.06f; + private float acc = 0.1f; public float Acc{ get{ return acc; } set{ acc = value; } @@ -40,7 +40,7 @@ public class PlayerStats : MonoBehaviour } //Players Number of Jumps - private int jumpNum = 60; ////// UPDATE TO 2 WHEN THE JUMP ISSUE IS FIXED + private int jumpNum = 2; ////// UPDATE TO 2 WHEN THE JUMP ISSUE IS FIXED public int JumpNum{ get{ return jumpNum; } set{ jumpNum = value; } diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1ec85c6..d1d8975 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -9,7 +9,7 @@ TagManager: - Default - TransparentFX - Ignore Raycast - - + - Player - Water - UI -