From 85f16b069755c10a959e98e4622923f4ecfdc507 Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Wed, 29 Sep 2021 18:47:21 +0200 Subject: [PATCH 1/6] Base Rigidbody Movement + FPS counter --- Assets/Scenes/SampleScene.unity | 214 +++++++++++++++++- Assets/Scripts/Character.meta | 8 + Assets/Scripts/{ => Character}/MouseLook.cs | 0 .../Scripts/{ => Character}/MouseLook.cs.meta | 0 .../{ => Character}/PlayerInteraction.cs | 0 .../{ => Character}/PlayerInteraction.cs.meta | 0 Assets/Scripts/Character/PlayerMovement.cs | 79 +++++++ .../{ => Character}/PlayerMovement.cs.meta | 0 Assets/Scripts/FPSCounter.cs | 21 ++ Assets/Scripts/FPSCounter.cs.meta | 11 + Assets/Scripts/PlayerMovement.cs | 102 --------- ProjectSettings/DynamicsManager.asset | 9 +- 12 files changed, 335 insertions(+), 109 deletions(-) create mode 100644 Assets/Scripts/Character.meta rename Assets/Scripts/{ => Character}/MouseLook.cs (100%) rename Assets/Scripts/{ => Character}/MouseLook.cs.meta (100%) rename Assets/Scripts/{ => Character}/PlayerInteraction.cs (100%) rename Assets/Scripts/{ => Character}/PlayerInteraction.cs.meta (100%) create mode 100644 Assets/Scripts/Character/PlayerMovement.cs rename Assets/Scripts/{ => Character}/PlayerMovement.cs.meta (100%) create mode 100644 Assets/Scripts/FPSCounter.cs create mode 100644 Assets/Scripts/FPSCounter.cs.meta delete mode 100644 Assets/Scripts/PlayerMovement.cs diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 861dc90..9369c8d 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -128,6 +128,36 @@ GameObject: m_CorrespondingSourceObject: {fileID: 8390537188327133021, guid: 6a86db7765f277243b912c20f451dc47, type: 3} m_PrefabInstance: {fileID: 8390537188401440993} m_PrefabAsset: {fileID: 0} +--- !u!136 &95348669 +CapsuleCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 95348668} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + m_Radius: 0.8 + m_Height: 3.5 + m_Direction: 1 + m_Center: {x: 0, y: 0, z: 0} +--- !u!54 &95348670 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 95348668} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 112 + m_CollisionDetection: 0 --- !u!114 &95348673 MonoBehaviour: m_ObjectHideFlags: 0 @@ -630,6 +660,7 @@ RectTransform: - {fileID: 1048269304} - {fileID: 1690461076} - {fileID: 114639928} + - {fileID: 1395840125} m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -788,6 +819,155 @@ Transform: m_CorrespondingSourceObject: {fileID: 494189295979627311, guid: 613866d46c759a848b2a462973745a74, type: 3} m_PrefabInstance: {fileID: 1799643402} m_PrefabAsset: {fileID: 0} +--- !u!1 &1395840124 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1395840125} + - component: {fileID: 1395840128} + - component: {fileID: 1395840127} + - component: {fileID: 1395840126} + m_Layer: 5 + m_Name: FPSText + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1395840125 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1395840124} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 708126143} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 0, y: -3.9089966} + m_SizeDelta: {x: 78.3094, y: 46.091} + m_Pivot: {x: 0, y: 1} +--- !u!114 &1395840126 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1395840124} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1866e0fb446be0342a91f95d71fc2c2d, type: 3} + m_Name: + m_EditorClassIdentifier: + fpsText: {fileID: 0} + deltaTime: 0 +--- !u!114 &1395840127 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1395840124} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: 187 FPS + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4278255384 + m_fontColor: {r: 0.09455109, g: 1, b: 0, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 15 + m_fontSizeBase: 15 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 1 + m_HorizontalAlignment: 4 + m_VerticalAlignment: 256 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &1395840128 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1395840124} + m_CullTransparentMesh: 1 --- !u!1 &1417065444 stripped GameObject: m_CorrespondingSourceObject: {fileID: 7029954221290272535, guid: bb7ccf3dcb131ed4cbdc3e66d7f136a0, type: 3} @@ -1113,7 +1293,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: timePeriod: 0.0002 - secondsOfDay: 30000 + secondsOfDay: 60000 --- !u!4 &1861247505 Transform: m_ObjectHideFlags: 0 @@ -1198,7 +1378,8 @@ PrefabInstance: propertyPath: m_Name value: Terrain objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 7029954221290272539, guid: bb7ccf3dcb131ed4cbdc3e66d7f136a0, type: 3} m_SourcePrefab: {fileID: 100100000, guid: bb7ccf3dcb131ed4cbdc3e66d7f136a0, type: 3} --- !u!1001 &8390537188401440993 PrefabInstance: @@ -1207,10 +1388,34 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 8390537187866079437, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: mouseSensitivityX + value: 600 + objectReference: {fileID: 0} + - target: {fileID: 8390537187866079437, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: mouseSensitivityY + value: 600 + objectReference: {fileID: 0} - target: {fileID: 8390537188327132961, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: interactionText value: objectReference: {fileID: 114639929} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: gravity + value: -9.86 + objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: jumpHeight + value: 3.5 + objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: sneakSpeed + value: 0.8 + objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: sprintSpeed + value: 1.1 + objectReference: {fileID: 0} - target: {fileID: 8390537188327133021, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: m_Name value: FirstPerson Player @@ -1225,7 +1430,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8390537188327133022, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: m_LocalPosition.y - value: 21.11 + value: 25.47 objectReference: {fileID: 0} - target: {fileID: 8390537188327133022, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: m_LocalPosition.z @@ -1259,5 +1464,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 8390537188327133023, guid: 6a86db7765f277243b912c20f451dc47, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 6a86db7765f277243b912c20f451dc47, type: 3} diff --git a/Assets/Scripts/Character.meta b/Assets/Scripts/Character.meta new file mode 100644 index 0000000..cf71a01 --- /dev/null +++ b/Assets/Scripts/Character.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d75be92c4c2783248ad8eb12442e96c4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/MouseLook.cs b/Assets/Scripts/Character/MouseLook.cs similarity index 100% rename from Assets/Scripts/MouseLook.cs rename to Assets/Scripts/Character/MouseLook.cs diff --git a/Assets/Scripts/MouseLook.cs.meta b/Assets/Scripts/Character/MouseLook.cs.meta similarity index 100% rename from Assets/Scripts/MouseLook.cs.meta rename to Assets/Scripts/Character/MouseLook.cs.meta diff --git a/Assets/Scripts/PlayerInteraction.cs b/Assets/Scripts/Character/PlayerInteraction.cs similarity index 100% rename from Assets/Scripts/PlayerInteraction.cs rename to Assets/Scripts/Character/PlayerInteraction.cs diff --git a/Assets/Scripts/PlayerInteraction.cs.meta b/Assets/Scripts/Character/PlayerInteraction.cs.meta similarity index 100% rename from Assets/Scripts/PlayerInteraction.cs.meta rename to Assets/Scripts/Character/PlayerInteraction.cs.meta diff --git a/Assets/Scripts/Character/PlayerMovement.cs b/Assets/Scripts/Character/PlayerMovement.cs new file mode 100644 index 0000000..f4a0283 --- /dev/null +++ b/Assets/Scripts/Character/PlayerMovement.cs @@ -0,0 +1,79 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerMovement : MonoBehaviour +{ + [Header("Speed Modifier")] + [SerializeField] private float speed = 12f; + [SerializeField] private float adjustedSpeed; + [SerializeField] private float sneakSpeed = 0.4f; + [SerializeField] private float sprintSpeed = 1.8f; + [SerializeField] private float jumpHeight = 3f; + + [Header("Ground Check")] + [SerializeField] private Transform groundCheck; + [SerializeField] private float groundDistance = 0.4f; + [SerializeField] private LayerMask groundMask; + + + private Rigidbody rb; + private bool isGrounded; + private bool isSprinting = false; + private bool isSneaking = false; + Vector3 movement; + + private void Start() + { + rb = GetComponent(); + } + + private void Update() + { + //Check every frame if the player stands on the ground + isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); + + //JUMP + if(Input.GetButtonDown("Jump") && isGrounded) + { + //Add Force Up To Jump + rb.AddForce(Vector3.up * jumpHeight * 100); //Times 100 -> so we can use smaller numbers in the editor + } + + + //Sprint + if (Input.GetButton("Sprint") && isGrounded) + { + Debug.Log("[PlayerController] Sprinting"); + isSprinting = true; + adjustedSpeed *= sprintSpeed; + } + else + { + isSprinting = false; + //Sneak + if (Input.GetButton("Sneak") && isGrounded) + { + Debug.Log("[PlayerController] Sneaking"); + isSprinting = true; + adjustedSpeed *= sneakSpeed; + } + else + { + isSneaking = false; + } + } + } + + private void FixedUpdate() + { + float x = Input.GetAxis("Horizontal"); + float z = Input.GetAxis("Vertical"); + + + movement = x * adjustedSpeed * transform.right + new Vector3(0, rb.velocity.y, 0) + z * adjustedSpeed * transform.forward; + rb.velocity = movement; + adjustedSpeed = speed; + } + +} diff --git a/Assets/Scripts/PlayerMovement.cs.meta b/Assets/Scripts/Character/PlayerMovement.cs.meta similarity index 100% rename from Assets/Scripts/PlayerMovement.cs.meta rename to Assets/Scripts/Character/PlayerMovement.cs.meta diff --git a/Assets/Scripts/FPSCounter.cs b/Assets/Scripts/FPSCounter.cs new file mode 100644 index 0000000..92e336d --- /dev/null +++ b/Assets/Scripts/FPSCounter.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +public class FPSCounter : MonoBehaviour +{ + public TMPro.TextMeshProUGUI fpsText; + public float deltaTime; + void Start() + { + fpsText = gameObject.GetComponent(); + } + + void Update() + { + deltaTime += (Time.deltaTime - deltaTime) * 0.1f; + float fps = 1.0f / deltaTime; + fpsText.text = Mathf.Ceil(fps).ToString() + "FPS"; + } +} diff --git a/Assets/Scripts/FPSCounter.cs.meta b/Assets/Scripts/FPSCounter.cs.meta new file mode 100644 index 0000000..e697081 --- /dev/null +++ b/Assets/Scripts/FPSCounter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1866e0fb446be0342a91f95d71fc2c2d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs deleted file mode 100644 index 734d303..0000000 --- a/Assets/Scripts/PlayerMovement.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class PlayerMovement : MonoBehaviour -{ - - [SerializeField] private CharacterController controller; - //[SerializeField] private Transform playerTransform; - [SerializeField] private float speed = 12f; - [SerializeField] private float airSpeed = 0.6f; - [SerializeField] private float sneakSpeed = 0.4f; - [SerializeField] private float sprintSpeed = 1.8f; - [SerializeField] private float sprintAirSpeed = 1.4f; - [SerializeField] private float gravity = -9.81f; - [SerializeField] private float jumpHeight = 3f; - - - [SerializeField] private Transform groundCheck; - [SerializeField] private float groundDistance = 0.4f; - [SerializeField] private LayerMask groundMask; - - private Vector3 velocity; - private bool isGrounded; - private bool isSprinting = false; - private bool isSneaking = false; - - void Update() - { - //GROUND CHECK - //Creates an invisible sphere on the bottom of our player - //And checks if it's colliding with something !with the "ground"-Mask in Unity! - isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); - - //Reset velocity if grounded - if (isGrounded && velocity.y < 0) - { - velocity.y = -2f; - } - - - //MOVEMENT - //Input.GetAxis is based on the Unity Input settings (edit -> Project Settings -> Input Manager) - float x = Input.GetAxis("Horizontal"); - float z = Input.GetAxis("Vertical"); - //Create move vector !in look direction! - Vector3 move; - - if (isGrounded)//for air control - { - move = transform.right * x + transform.forward * z; - - //SPRINT - if (Input.GetButton("Sprint")) - { - move *= sprintSpeed; - isSprinting = true; - } - else - { - //SNEAK - if (Input.GetButton("Sneak")) - { - move *= sneakSpeed; - isSneaking = true; - //Kommt mit character model und animations - } - else - { - isSneaking = false; - } - isSprinting = false; - } - - //JUMP - if (Input.GetButtonDown("Jump")) - { - velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity); - } - } - else//Air control - { - if (isSprinting) - { - move = transform.right * x * airSpeed * sprintAirSpeed + transform.forward * z * airSpeed * sprintAirSpeed; - } - else - { - move = transform.right * x * airSpeed + transform.forward * z * airSpeed; - } - } - - //Apply move vector - controller.Move(move * speed * Time.deltaTime); - - //Add gravity to current velocity - velocity.y += gravity * Time.deltaTime; - //apply gravity - controller.Move(velocity * Time.deltaTime);//nochmal time.deltatime wegen irgendwas mit physikalischer Formel und so - - } -} diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index cdc1f3e..51937e5 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -3,10 +3,11 @@ --- !u!55 &1 PhysicsManager: m_ObjectHideFlags: 0 - serializedVersion: 11 - m_Gravity: {x: 0, y: -9.81, z: 0} + serializedVersion: 13 + m_Gravity: {x: 0, y: -12, z: 0} m_DefaultMaterial: {fileID: 0} m_BounceThreshold: 2 + m_DefaultMaxDepenetrationVelocity: 10 m_SleepThreshold: 0.005 m_DefaultContactOffset: 0.01 m_DefaultSolverIterations: 6 @@ -22,6 +23,7 @@ PhysicsManager: m_AutoSyncTransforms: 0 m_ReuseCollisionCallbacks: 1 m_ClothInterCollisionSettingsToggle: 0 + m_ClothGravity: {x: 0, y: -9.81, z: 0} m_ContactPairsMode: 0 m_BroadphaseType: 0 m_WorldBounds: @@ -31,4 +33,5 @@ PhysicsManager: m_FrictionType: 0 m_EnableEnhancedDeterminism: 0 m_EnableUnifiedHeightmaps: 1 - m_DefaultMaxAngluarSpeed: 7 + m_SolverType: 0 + m_DefaultMaxAngularSpeed: 7 From f7cd996097c7da1c2f711664b460f0bc92370633 Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Wed, 29 Sep 2021 18:58:26 +0200 Subject: [PATCH 2/6] Updated Unity Version to 2021.1.22f1) --- Assets/Prefabs/FirstPerson Player.prefab | 31 ++++------------------ Assets/Scenes/SampleScene.unity | 7 +++-- Assets/Scripts/Character/PlayerMovement.cs | 6 ++--- Packages/manifest.json | 6 ++--- Packages/packages-lock.json | 8 +++--- ProjectSettings/ProjectVersion.txt | 4 +-- 6 files changed, 20 insertions(+), 42 deletions(-) diff --git a/Assets/Prefabs/FirstPerson Player.prefab b/Assets/Prefabs/FirstPerson Player.prefab index 8f1d26b..d8a0c99 100644 --- a/Assets/Prefabs/FirstPerson Player.prefab +++ b/Assets/Prefabs/FirstPerson Player.prefab @@ -138,7 +138,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 8390537188327133022} - - component: {fileID: 8390537188327133023} - component: {fileID: 8390537188327133020} - component: {fileID: 8390537188327132961} m_Layer: 0 @@ -165,24 +164,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!143 &8390537188327133023 -CharacterController: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8390537188327133021} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Height: 3.8 - m_Radius: 0.6 - m_SlopeLimit: 45 - m_StepOffset: 0.7 - m_SkinWidth: 0.08 - m_MinMoveDistance: 0.001 - m_Center: {x: 0, y: 0, z: 0} --- !u!114 &8390537188327133020 MonoBehaviour: m_ObjectHideFlags: 0 @@ -195,14 +176,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fcb8e32fc55ebe9478dee06683e84d92, type: 3} m_Name: m_EditorClassIdentifier: - controller: {fileID: 8390537188327133023} speed: 12 - airSpeed: 0.7 - sneakSpeed: 0.4 - sprintSpeed: 1.8 - sprintAirSpeed: 1.9 - gravity: -19.62 - jumpHeight: 4 + adjustedSpeed: 0 + sneakSpeed: 0.8 + sprintSpeed: 1.1 + jumpHeight: 3.5 groundCheck: {fileID: 8390537187855206696} groundDistance: 0.4 groundMask: @@ -273,6 +251,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 9369c8d..1d7dfa5 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.2277222, g: 0.2251251, b: 0.2237271, a: 1} + m_IndirectSpecularColor: {r: 0.5996083, g: 0.5927744, b: 0.588867, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -1410,7 +1410,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: sneakSpeed - value: 0.8 + value: 0.9 objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: sprintSpeed @@ -1464,6 +1464,5 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - m_RemovedComponents: - - {fileID: 8390537188327133023, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 6a86db7765f277243b912c20f451dc47, type: 3} diff --git a/Assets/Scripts/Character/PlayerMovement.cs b/Assets/Scripts/Character/PlayerMovement.cs index f4a0283..0dcaf37 100644 --- a/Assets/Scripts/Character/PlayerMovement.cs +++ b/Assets/Scripts/Character/PlayerMovement.cs @@ -7,9 +7,9 @@ public class PlayerMovement : MonoBehaviour [Header("Speed Modifier")] [SerializeField] private float speed = 12f; [SerializeField] private float adjustedSpeed; - [SerializeField] private float sneakSpeed = 0.4f; - [SerializeField] private float sprintSpeed = 1.8f; - [SerializeField] private float jumpHeight = 3f; + [SerializeField] private float sneakSpeed = 0.9f; + [SerializeField] private float sprintSpeed = 1.1f; + [SerializeField] private float jumpHeight = 3.5f; [Header("Ground Check")] [SerializeField] private Transform groundCheck; diff --git a/Packages/manifest.json b/Packages/manifest.json index 395e7d7..f83d9a4 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,12 +1,12 @@ { "dependencies": { "com.unity.collab-proxy": "1.9.0", - "com.unity.ide.rider": "2.0.7", + "com.unity.ide.rider": "3.0.7", "com.unity.ide.visualstudio": "2.0.11", - "com.unity.ide.vscode": "1.2.3", + "com.unity.ide.vscode": "1.2.4", "com.unity.test-framework": "1.1.29", "com.unity.textmeshpro": "3.0.6", - "com.unity.timeline": "1.4.8", + "com.unity.timeline": "1.5.6", "com.unity.ugui": "1.0.0", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index f25244e..316e621 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -15,11 +15,11 @@ "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "2.0.7", + "version": "3.0.7", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.1" + "com.unity.ext.nunit": "1.0.6" }, "url": "https://packages.unity.com" }, @@ -33,7 +33,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.vscode": { - "version": "1.2.3", + "version": "1.2.4", "depth": 0, "source": "registry", "dependencies": {}, @@ -60,7 +60,7 @@ "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.4.8", + "version": "1.5.6", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 5650251..fe1188f 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2020.3.18f1 -m_EditorVersionWithRevision: 2020.3.18f1 (a7d1c678663c) +m_EditorVersion: 2021.1.22f1 +m_EditorVersionWithRevision: 2021.1.22f1 (a137e5fb0427) From d211c0468e73b5521e116cfc1169310b825d8e52 Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Wed, 29 Sep 2021 19:57:09 +0200 Subject: [PATCH 3/6] Update Movement --- Assets/Scripts/Character/PlayerMovement.cs | 86 +++++++++++++++------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/Assets/Scripts/Character/PlayerMovement.cs b/Assets/Scripts/Character/PlayerMovement.cs index 0dcaf37..ce91352 100644 --- a/Assets/Scripts/Character/PlayerMovement.cs +++ b/Assets/Scripts/Character/PlayerMovement.cs @@ -4,23 +4,29 @@ using UnityEngine; public class PlayerMovement : MonoBehaviour { - [Header("Speed Modifier")] + [Header("Force Modifier")] [SerializeField] private float speed = 12f; - [SerializeField] private float adjustedSpeed; - [SerializeField] private float sneakSpeed = 0.9f; - [SerializeField] private float sprintSpeed = 1.1f; - [SerializeField] private float jumpHeight = 3.5f; + + [SerializeField] private float sneakSpeedModifier = 0.7f; + [SerializeField] private float sprintSpeedModifier = 1.4f; + [SerializeField] private float jumpSprintSpeedModifier = 20f; + [SerializeField] private float jumpForce = 3.5f; + [SerializeField] private float fallMultiplier = 2.5f; [Header("Ground Check")] [SerializeField] private Transform groundCheck; [SerializeField] private float groundDistance = 0.4f; [SerializeField] private LayerMask groundMask; + public bool isSprinting = false; + public bool isSneaking = false; private Rigidbody rb; private bool isGrounded; - private bool isSprinting = false; - private bool isSneaking = false; + private float modifiedSpeed; + float x; + float z; + Vector3 movement; private void Start() @@ -29,24 +35,33 @@ public class PlayerMovement : MonoBehaviour } private void Update() + { + Grounded(); + Jump(); + MovementSpeed(); + } + + private void FixedUpdate() + { + rb.velocity = movement; + + } + + private void Grounded() { //Check every frame if the player stands on the ground isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); - - //JUMP - if(Input.GetButtonDown("Jump") && isGrounded) - { - //Add Force Up To Jump - rb.AddForce(Vector3.up * jumpHeight * 100); //Times 100 -> so we can use smaller numbers in the editor - } + } + private void MovementSpeed() + { + modifiedSpeed = speed; //RESET speed //Sprint if (Input.GetButton("Sprint") && isGrounded) { - Debug.Log("[PlayerController] Sprinting"); isSprinting = true; - adjustedSpeed *= sprintSpeed; + modifiedSpeed *= sprintSpeedModifier; } else { @@ -54,26 +69,41 @@ public class PlayerMovement : MonoBehaviour //Sneak if (Input.GetButton("Sneak") && isGrounded) { - Debug.Log("[PlayerController] Sneaking"); - isSprinting = true; - adjustedSpeed *= sneakSpeed; + isSneaking = true; + modifiedSpeed *= sneakSpeedModifier; } else { isSneaking = false; } - } + } + + //Sprint jump + if (isSprinting && Input.GetButtonDown("Jump")) + { + Debug.Log("Jump Sprint"); + rb.AddRelativeForce(Vector3.forward * jumpSprintSpeedModifier); + } + + + x = Input.GetAxis("Horizontal"); + z = Input.GetAxis("Vertical"); + + movement = x * modifiedSpeed * transform.right + new Vector3(0, rb.velocity.y, 0) + z * modifiedSpeed * transform.forward; } - private void FixedUpdate() + private void Jump() { - float x = Input.GetAxis("Horizontal"); - float z = Input.GetAxis("Vertical"); + //Better Falling + if(rb.velocity.y < 0) + { + rb.velocity += Vector3.up * Physics.gravity.y * (fallMultiplier - 1) * Time.deltaTime; + } - - movement = x * adjustedSpeed * transform.right + new Vector3(0, rb.velocity.y, 0) + z * adjustedSpeed * transform.forward; - rb.velocity = movement; - adjustedSpeed = speed; + if (Input.GetButtonDown("Jump") && isGrounded) + { + //Add Force Up To Jump + rb.AddForce(Vector3.up * jumpForce * 100); //Times 100 -> so we can use smaller numbers in the editor + } } - } From 97d5ba183bf61c3fb965f5768068c0199495a9e7 Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Wed, 29 Sep 2021 20:12:28 +0200 Subject: [PATCH 4/6] Update PlayerMovement.cs --- Assets/Scripts/Character/PlayerMovement.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/Character/PlayerMovement.cs b/Assets/Scripts/Character/PlayerMovement.cs index ce91352..e11bc10 100644 --- a/Assets/Scripts/Character/PlayerMovement.cs +++ b/Assets/Scripts/Character/PlayerMovement.cs @@ -24,6 +24,7 @@ public class PlayerMovement : MonoBehaviour private Rigidbody rb; private bool isGrounded; private float modifiedSpeed; + private bool isJumpSprinting = false; float x; float z; @@ -51,6 +52,12 @@ public class PlayerMovement : MonoBehaviour { //Check every frame if the player stands on the ground isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); + + if (isGrounded) + { + isJumpSprinting = false; + } + } private void MovementSpeed() { @@ -76,15 +83,7 @@ public class PlayerMovement : MonoBehaviour { isSneaking = false; } - } - - //Sprint jump - if (isSprinting && Input.GetButtonDown("Jump")) - { - Debug.Log("Jump Sprint"); - rb.AddRelativeForce(Vector3.forward * jumpSprintSpeedModifier); - } - + } x = Input.GetAxis("Horizontal"); z = Input.GetAxis("Vertical"); From 9425d95ce2a43e923a07e800d2e283a8345c40fd Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Wed, 29 Sep 2021 20:12:43 +0200 Subject: [PATCH 5/6] Update SampleScene.unity --- Assets/Scenes/SampleScene.unity | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 1d7dfa5..76ae054 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -1404,17 +1404,37 @@ PrefabInstance: propertyPath: gravity value: -9.86 objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: airSpeed + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: jumpForce + value: 4 + objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: jumpHeight value: 3.5 objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: sneakSpeed - value: 0.9 + value: 0.7 objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: sprintSpeed - value: 1.1 + value: 1.7 + objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: fallMultiplier + value: 1.5 + objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: sprintJumpSpeed + value: 10 + objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: jumpSprintSpeedModifier + value: 2000 objectReference: {fileID: 0} - target: {fileID: 8390537188327133021, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: m_Name From 0faf506d5a601d99df0888ae96e3fded634bb5c4 Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Fri, 1 Oct 2021 11:42:01 +0200 Subject: [PATCH 6/6] Update SampleScene.unity --- Assets/Scenes/SampleScene.unity | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 76ae054..e080abe 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -1410,7 +1410,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: jumpForce - value: 4 + value: 3.5 objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: jumpHeight @@ -1426,12 +1426,16 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: fallMultiplier - value: 1.5 + value: 1.8 objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: sprintJumpSpeed value: 10 objectReference: {fileID: 0} + - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: sneakSpeedModifier + value: 0.6 + objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: jumpSprintSpeedModifier value: 2000