From 8610868924365c2a7444d470faa548f796584f33 Mon Sep 17 00:00:00 2001 From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com> Date: Sun, 30 Mar 2025 17:26:31 +0100 Subject: [PATCH] Changed how slope detection works There is a bug with the camera --- Assets/Scenes/SampleScene.unity | 194 ++++++++++-------- Assets/Scripts/Player/CameraController.cs | 4 + Assets/Scripts/Player/PlayerFixedUpdate.cs | 2 +- Assets/Scripts/Player/PlayerMovement.cs | 6 +- Assets/Scripts/Player/PlayerUpdate.cs | 8 +- Assets/Scripts/Player/SlidingMovement.cs | 2 +- .../Materials/Prototype_512x512_White.mat | 4 + 7 files changed, 129 insertions(+), 91 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index c3f931e..a3c4fca 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -623,9 +623,6 @@ MonoBehaviour: m_GroundMask: serializedVersion: 2 m_Bits: 3072 - m_SlopeMask: - serializedVersion: 2 - m_Bits: 2048 m_SlideRequiredSpeed: 1 m_SlideScaler: 0.6 m_SlideDrag: 3 @@ -1775,7 +1772,7 @@ Canvas: m_Enabled: 1 serializedVersion: 3 m_RenderMode: 1 - m_Camera: {fileID: 963194227} + m_Camera: {fileID: 0} m_PlaneDistance: 1 m_PixelPerfect: 1 m_ReceivesEvents: 1 @@ -4140,6 +4137,115 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 543919274} m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1 &555852633 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 555852637} + - component: {fileID: 555852636} + - component: {fileID: 555852635} + - component: {fileID: 555852634} + m_Layer: 0 + m_Name: Camera + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &555852634 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 555852633} + m_Enabled: 1 +--- !u!114 &555852635 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 555852633} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5cfd42fc2ed2f504dae2b9e7095401cf, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Sensitivity: {x: 1200, y: 800} + m_MaxAngle: 85 + m_Orientation: {fileID: 166780449} + m_Tracking: {fileID: 963194228} +--- !u!20 &555852636 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 555852633} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_FocusDistance: 10 + m_FocalLength: 50 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &555852637 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 555852633} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 16.635672, y: 8.343683, z: -5.1720905} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &609667110 GameObject: m_ObjectHideFlags: 0 @@ -7082,75 +7188,13 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 963194228} - - component: {fileID: 963194229} - - component: {fileID: 963194227} - - component: {fileID: 963194226} m_Layer: 0 - m_Name: Main Camera + m_Name: CameraHolder m_TagString: MainCamera m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!81 &963194226 -AudioListener: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 963194225} - m_Enabled: 1 ---- !u!20 &963194227 -Camera: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 963194225} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} - m_projectionMatrixMode: 1 - m_GateFitMode: 2 - m_FOVAxisMode: 0 - m_Iso: 200 - m_ShutterSpeed: 0.005 - m_Aperture: 16 - m_FocusDistance: 10 - m_FocalLength: 50 - m_BladeCount: 5 - m_Curvature: {x: 2, y: 11} - m_BarrelClipping: 0.25 - m_Anamorphism: 0 - m_SensorSize: {x: 36, y: 24} - m_LensShift: {x: 0, y: 0} - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 1 - m_AllowMSAA: 1 - m_AllowDynamicResolution: 0 - m_ForceIntoRT: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 --- !u!4 &963194228 Transform: m_ObjectHideFlags: 0 @@ -7166,21 +7210,6 @@ Transform: m_Children: [] m_Father: {fileID: 1174770951} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &963194229 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 963194225} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 5cfd42fc2ed2f504dae2b9e7095401cf, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Sensitivity: {x: 1200, y: 800} - m_MaxAngle: 85 - m_Orientation: {fileID: 166780449} --- !u!1 &974940780 GameObject: m_ObjectHideFlags: 0 @@ -13511,3 +13540,4 @@ SceneRoots: - {fileID: 2043134296} - {fileID: 236811070} - {fileID: 1971092436} + - {fileID: 555852637} diff --git a/Assets/Scripts/Player/CameraController.cs b/Assets/Scripts/Player/CameraController.cs index 09d2168..77d33fd 100644 --- a/Assets/Scripts/Player/CameraController.cs +++ b/Assets/Scripts/Player/CameraController.cs @@ -12,6 +12,7 @@ public class CameraController : MonoBehaviour [Header("References")] [SerializeField] Transform m_Orientation; + [SerializeField] Transform m_Tracking; // Private variables // @@ -65,5 +66,8 @@ public class CameraController : MonoBehaviour // Applies the rotation to the objects within Unity m_Orientation.rotation = Quaternion.Euler(0, m_Rotation.y, 0); transform.rotation = Quaternion.Euler(m_Rotation.x, m_Rotation.y, 0); + + // Sets its location to where it is tracking + transform.position = m_Tracking.position; } } diff --git a/Assets/Scripts/Player/PlayerFixedUpdate.cs b/Assets/Scripts/Player/PlayerFixedUpdate.cs index 5f69db3..93c4e0a 100644 --- a/Assets/Scripts/Player/PlayerFixedUpdate.cs +++ b/Assets/Scripts/Player/PlayerFixedUpdate.cs @@ -28,7 +28,7 @@ public partial class PlayerMovement : MonoBehaviour if (m_OnSlope) { // Calculates better move direction for sliding - m_MoveDir = Vector3.ProjectOnPlane(m_MoveDir, m_SlopeHit.normal).normalized; + m_MoveDir = Vector3.ProjectOnPlane(m_MoveDir, m_StandingOn.normal).normalized; } // Runs correct update function depending on player state diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index 601690a..e1beab9 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -15,7 +15,6 @@ public partial class PlayerMovement : MonoBehaviour [Header("Ground Check")] [SerializeField] float m_PlayerHeight; [SerializeField] LayerMask m_GroundMask; - [SerializeField] LayerMask m_SlopeMask; [Header("Sliding Settings")] [SerializeField] float m_SlideRequiredSpeed; @@ -71,9 +70,8 @@ public partial class PlayerMovement : MonoBehaviour bool m_FlippedWallRideDirectionFirstFrame = false; Vector3 m_LastWallNormal; - // Raycast hit objects - RaycastHit m_GroundHit; - RaycastHit m_SlopeHit; + // What the player is standing on + RaycastHit m_StandingOn; // BoxCollider m_WallCollider; diff --git a/Assets/Scripts/Player/PlayerUpdate.cs b/Assets/Scripts/Player/PlayerUpdate.cs index 6eb1451..99b705b 100644 --- a/Assets/Scripts/Player/PlayerUpdate.cs +++ b/Assets/Scripts/Player/PlayerUpdate.cs @@ -43,11 +43,13 @@ public partial class PlayerMovement : MonoBehaviour private void Update() { // Performs raycasts to see what the player is standing on - m_Grounded = Physics.Raycast(transform.position, Vector3.down, out m_GroundHit, m_PlayerHeight * 0.5f + 0.3f, m_GroundMask); - m_OnSlope = Physics.Raycast(transform.position, Vector3.down, out m_SlopeHit, m_PlayerHeight * 0.5f + 0.3f, m_SlopeMask); + m_Grounded = Physics.Raycast(transform.position, Vector3.down, out m_StandingOn, m_PlayerHeight * 0.5f + 0.3f, m_GroundMask); + m_OnSlope = m_StandingOn.normal != new Vector3(0.0f, 1.0f, 0.0f) && m_Grounded; + + Debug.Log(m_OnSlope + " | " + m_StandingOn.normal); // Checks the player is far enough of the ground to start wall running - m_IsFarEnoughOffGroundToWallRide = m_GroundHit.distance > m_DistanceOfFloorToWallRide; + m_IsFarEnoughOffGroundToWallRide = m_StandingOn.distance > m_DistanceOfFloorToWallRide; // Updates the state of the user input UpdateInput(); diff --git a/Assets/Scripts/Player/SlidingMovement.cs b/Assets/Scripts/Player/SlidingMovement.cs index db97d51..ca918c9 100644 --- a/Assets/Scripts/Player/SlidingMovement.cs +++ b/Assets/Scripts/Player/SlidingMovement.cs @@ -31,7 +31,7 @@ public partial class PlayerMovement : MonoBehaviour // Correctly applies force on slopes if (m_OnSlope) { - Vector3 slopeDir = m_SlopeHit.normal; + Vector3 slopeDir = m_StandingOn.normal; slopeDir.y = 0.0f - slopeDir.y; m_Body.AddForce(slopeDir.normalized * m_SlideSpeed * m_Body.mass * 10, ForceMode.Force); } diff --git a/Assets/Thirdparty/Ciathyza/Gridbox Prototype Materials/Materials/Prototype_512x512_White.mat b/Assets/Thirdparty/Ciathyza/Gridbox Prototype Materials/Materials/Prototype_512x512_White.mat index 8039b27..c365faa 100644 --- a/Assets/Thirdparty/Ciathyza/Gridbox Prototype Materials/Materials/Prototype_512x512_White.mat +++ b/Assets/Thirdparty/Ciathyza/Gridbox Prototype Materials/Materials/Prototype_512x512_White.mat @@ -52,6 +52,10 @@ Material: m_Texture: {fileID: 2800000, guid: 9397418d1d7b12543bf27fb61b93bbea, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _EmissionMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1}