diff --git a/Assets/RenderPipeline.meta b/Assets/RenderPipeline.meta new file mode 100644 index 0000000..9625b58 --- /dev/null +++ b/Assets/RenderPipeline.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 816a0d14526c1de4d969eba2857628d8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RenderPipeline/DefaultLightingSettings.lighting b/Assets/RenderPipeline/DefaultLightingSettings.lighting new file mode 100644 index 0000000..c7a5152 --- /dev/null +++ b/Assets/RenderPipeline/DefaultLightingSettings.lighting @@ -0,0 +1,63 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!850595691 &4890085278179872738 +LightingSettings: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: DefaultLightingSettings + serializedVersion: 2 + m_GIWorkflowMode: 1 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_RealtimeEnvironmentLighting: 1 + m_BounceScale: 1 + m_AlbedoBoost: 1 + m_IndirectOutputScale: 1 + m_UsingShadowmask: 1 + m_BakeBackend: 1 + m_LightmapMaxSize: 1024 + m_BakeResolution: 40 + m_Padding: 2 + m_TextureCompression: 1 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAO: 0 + m_MixedBakeMode: 2 + m_LightmapsBakeMode: 1 + m_FilterMode: 1 + m_LightmapParameters: {fileID: 0} + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_RealtimeResolution: 2 + m_ForceWhiteAlbedo: 0 + m_ForceUpdates: 0 + m_FinalGather: 0 + m_FinalGatherRayCount: 256 + m_FinalGatherFiltering: 1 + m_PVRCulling: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_LightProbeSampleCountMultiplier: 4 + m_PVRBounces: 2 + m_PVRRussianRouletteStartBounce: 2 + m_PVREnvironmentMIS: 1 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 diff --git a/Assets/RenderPipeline/DefaultLightingSettings.lighting.meta b/Assets/RenderPipeline/DefaultLightingSettings.lighting.meta new file mode 100644 index 0000000..479be45 --- /dev/null +++ b/Assets/RenderPipeline/DefaultLightingSettings.lighting.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eab3e4c589c0a1147a910511c80f5e0c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RenderPipeline/UniversalRenderPipelineAsset.asset b/Assets/RenderPipeline/UniversalRenderPipelineAsset.asset new file mode 100644 index 0000000..3763216 --- /dev/null +++ b/Assets/RenderPipeline/UniversalRenderPipelineAsset.asset @@ -0,0 +1,55 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bf2edee5c58d82540a51f03df9d42094, type: 3} + m_Name: UniversalRenderPipelineAsset + m_EditorClassIdentifier: + k_AssetVersion: 5 + k_AssetPreviousVersion: 5 + m_RendererType: 1 + m_RendererData: {fileID: 0} + m_RendererDataList: + - {fileID: 11400000, guid: 329556371b5b38d4b97bf007b4a0cfcb, type: 2} + m_DefaultRendererIndex: 0 + m_RequireDepthTexture: 0 + m_RequireOpaqueTexture: 0 + m_OpaqueDownsampling: 1 + m_SupportsTerrainHoles: 1 + m_SupportsHDR: 1 + m_MSAA: 4 + m_RenderScale: 1 + m_MainLightRenderingMode: 1 + m_MainLightShadowsSupported: 1 + m_MainLightShadowmapResolution: 2048 + m_AdditionalLightsRenderingMode: 1 + m_AdditionalLightsPerObjectLimit: 4 + m_AdditionalLightShadowsSupported: 0 + m_AdditionalLightsShadowmapResolution: 512 + m_ShadowDistance: 50 + m_ShadowCascades: 0 + m_Cascade2Split: 0.25 + m_Cascade4Split: {x: 0.067, y: 0.2, z: 0.467} + m_ShadowDepthBias: 1 + m_ShadowNormalBias: 1 + m_SoftShadowsSupported: 1 + m_UseSRPBatcher: 1 + m_SupportsDynamicBatching: 0 + m_MixedLightingSupported: 1 + m_DebugLevel: 0 + m_UseAdaptivePerformance: 1 + m_ColorGradingMode: 1 + m_ColorGradingLutSize: 32 + m_ShadowType: 1 + m_LocalShadowsSupported: 0 + m_LocalShadowsAtlasResolution: 256 + m_MaxPixelLights: 0 + m_ShadowAtlasResolution: 256 + m_ShaderVariantLogLevel: 0 diff --git a/Assets/RenderPipeline/UniversalRenderPipelineAsset.asset.meta b/Assets/RenderPipeline/UniversalRenderPipelineAsset.asset.meta new file mode 100644 index 0000000..f46cba2 --- /dev/null +++ b/Assets/RenderPipeline/UniversalRenderPipelineAsset.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 714d5817425984e47bcc98849464c172 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RenderPipeline/UniversalRenderPipelineAsset_Renderer.asset b/Assets/RenderPipeline/UniversalRenderPipelineAsset_Renderer.asset new file mode 100644 index 0000000..9bcfe4d --- /dev/null +++ b/Assets/RenderPipeline/UniversalRenderPipelineAsset_Renderer.asset @@ -0,0 +1,37 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: de640fe3d0db1804a85f9fc8f5cadab6, type: 3} + m_Name: UniversalRenderPipelineAsset_Renderer + m_EditorClassIdentifier: + m_RendererFeatures: [] + m_RendererFeatureMap: + postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} + shaders: + blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3} + copyDepthPS: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3} + screenSpaceShadowPS: {fileID: 4800000, guid: 0f854b35a0cf61a429bd5dcfea30eddd, type: 3} + samplingPS: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3} + fallbackErrorPS: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3} + m_OpaqueLayerMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_TransparentLayerMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_DefaultStencilState: + overrideStencilState: 0 + stencilReference: 0 + stencilCompareFunction: 8 + passOperation: 0 + failOperation: 0 + zFailOperation: 0 + m_ShadowTransparentReceive: 1 diff --git a/Assets/RenderPipeline/UniversalRenderPipelineAsset_Renderer.asset.meta b/Assets/RenderPipeline/UniversalRenderPipelineAsset_Renderer.asset.meta new file mode 100644 index 0000000..cf1d019 --- /dev/null +++ b/Assets/RenderPipeline/UniversalRenderPipelineAsset_Renderer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 329556371b5b38d4b97bf007b4a0cfcb +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ScriptableObjects.meta b/Assets/ScriptableObjects.meta new file mode 100644 index 0000000..9102701 --- /dev/null +++ b/Assets/ScriptableObjects.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6e5509da920e35841a6845fa3d020421 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ScriptableObjects/MoveStyles.meta b/Assets/ScriptableObjects/MoveStyles.meta new file mode 100644 index 0000000..ccdcd22 --- /dev/null +++ b/Assets/ScriptableObjects/MoveStyles.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 74af483c66a70cf49aa4d45415d2cfcd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ScriptableObjects/MoveStyles/Crouching.asset b/Assets/ScriptableObjects/MoveStyles/Crouching.asset new file mode 100644 index 0000000..8e371b9 --- /dev/null +++ b/Assets/ScriptableObjects/MoveStyles/Crouching.asset @@ -0,0 +1,22 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c7827ce96d9ff12458f0de236abbab9b, type: 3} + m_Name: Crouching + m_EditorClassIdentifier: + TargetVelocity: 4 + StopVelocity: 3 + Acceleration: 20 + AirAcceleration: 15 + Friction: 20 + AirFriction: 15 + JumpVelocity: 5 + LeanDegrees: 1 diff --git a/Assets/ScriptableObjects/MoveStyles/Crouching.asset.meta b/Assets/ScriptableObjects/MoveStyles/Crouching.asset.meta new file mode 100644 index 0000000..941e718 --- /dev/null +++ b/Assets/ScriptableObjects/MoveStyles/Crouching.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2d9739d3745581a41ae0ed6a569766d5 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ScriptableObjects/MoveStyles/Running.asset b/Assets/ScriptableObjects/MoveStyles/Running.asset new file mode 100644 index 0000000..c3f79a2 --- /dev/null +++ b/Assets/ScriptableObjects/MoveStyles/Running.asset @@ -0,0 +1,22 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c7827ce96d9ff12458f0de236abbab9b, type: 3} + m_Name: Running + m_EditorClassIdentifier: + TargetVelocity: 10 + StopVelocity: 3 + Acceleration: 10 + AirAcceleration: 5 + Friction: 8 + AirFriction: 4 + JumpVelocity: 8 + LeanDegrees: 2 diff --git a/Assets/ScriptableObjects/MoveStyles/Running.asset.meta b/Assets/ScriptableObjects/MoveStyles/Running.asset.meta new file mode 100644 index 0000000..464acb2 --- /dev/null +++ b/Assets/ScriptableObjects/MoveStyles/Running.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 550df8ac62d76a64a8c621ea6b32398f +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Options.cs b/Assets/Scripts/Options.cs new file mode 100644 index 0000000..ab954aa --- /dev/null +++ b/Assets/Scripts/Options.cs @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace NeonTea.Quakeball { + /// Container for user-selected options. + public class OptionsData { + public bool InvertVerticalLook = false; + public float LookSensitivity = 0.15f; + } + + public class Options : MonoBehaviour { + private static OptionsData Singleton = new OptionsData(); + + public static OptionsData Get() { + return Singleton; + } + } +} diff --git a/Assets/Scripts/Options.cs.meta b/Assets/Scripts/Options.cs.meta new file mode 100644 index 0000000..01fa80c --- /dev/null +++ b/Assets/Scripts/Options.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0ca0b306afdebee4a9258b12c4ca457b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player.meta b/Assets/Scripts/Player.meta new file mode 100644 index 0000000..7c838f6 --- /dev/null +++ b/Assets/Scripts/Player.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 547a2f92b7463b5479ca4bf370d32fa6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/LocalPlayer.cs b/Assets/Scripts/Player/LocalPlayer.cs new file mode 100644 index 0000000..86f14d8 --- /dev/null +++ b/Assets/Scripts/Player/LocalPlayer.cs @@ -0,0 +1,65 @@ +using UnityEngine; +using UnityEngine.InputSystem; + +namespace NeonTea.Quakeball.Player { + /// A controller class for a local player. Handles input and updates the relevant components. + [RequireComponent(typeof(Player))] + public class LocalPlayer : MonoBehaviour { + public Transform Camera; + + private float Lean = 0; + + private Player Player; + private InputAction LookAction; + private InputAction MoveAction; + private InputAction CrouchAction; + private InputAction JumpAction; + + private void Awake() { + Player = GetComponent(); + + CrouchAction = new InputAction("crouch", binding: "/buttonEast"); + CrouchAction.AddBinding("/leftShift"); + CrouchAction.Enable(); + + JumpAction = new InputAction("crouch", binding: "/buttonSouth"); + JumpAction.AddBinding("/space"); + JumpAction.Enable(); + + LookAction = new InputAction("look", binding: "/leftStick"); + LookAction.AddBinding("/delta"); + LookAction.Enable(); + + MoveAction = new InputAction("move", binding: "/rightStick"); + MoveAction.AddCompositeBinding("Dpad") + .With("Up", "/w") + .With("Down", "/s") + .With("Left", "/a") + .With("Right", "/d"); + MoveAction.Enable(); + } + + private void Start() { + Cursor.visible = false; + Cursor.lockState = CursorLockMode.Locked; + } + + private void Update() { + OptionsData Opts = Options.Get(); + + Vector2 MovementInput = MoveAction.ReadValue(); + Vector3 Move = new Vector3(MovementInput.x, 0, MovementInput.y); + Move = Quaternion.Euler(0, Player.Yaw, 0) * Move; + Player.MoveDirection = Move; + Player.MoveStyle = CrouchAction.ReadValue() > 0 ? Player.CrouchingMoveStyle : Player.RunningMoveStyle; + Player.Jumping = JumpAction.ReadValue() > 0; + + Vector2 LookInput = LookAction.ReadValue() * Opts.LookSensitivity; + Player.Pitch = Mathf.Clamp(Player.Pitch - LookInput.y * (Opts.InvertVerticalLook ? -1 : 1), -90, 90); + Player.Yaw += LookInput.x; + float TargetLean = -Vector3.Dot(Player.GroundVelocity / Player.MoveStyle.TargetVelocity, Camera.right) * Player.MoveStyle.LeanDegrees; + Lean = Mathf.Lerp(Lean, TargetLean, 10f * Time.deltaTime); + Camera.localEulerAngles = new Vector3(Player.Pitch, Player.Yaw, Lean); + } + } +} diff --git a/Assets/Scripts/Player/LocalPlayer.cs.meta b/Assets/Scripts/Player/LocalPlayer.cs.meta new file mode 100644 index 0000000..ee3350c --- /dev/null +++ b/Assets/Scripts/Player/LocalPlayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f6e08271c272323469510daa22c35599 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: -20 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/MoveStyle.cs b/Assets/Scripts/Player/MoveStyle.cs new file mode 100644 index 0000000..488e894 --- /dev/null +++ b/Assets/Scripts/Player/MoveStyle.cs @@ -0,0 +1,24 @@ +using UnityEngine; + +namespace NeonTea.Quakeball.Player { + /// Different modes of transportation. + [CreateAssetMenu(fileName = "Moving", menuName = "Quakeball/MoveStyle")] + public class MoveStyle : ScriptableObject { + /// The target velocity to accelerate towards. + public float TargetVelocity; + /// When decelerating, the speed at which the deceleration no longer decelerates. + public float StopVelocity; + /// The acceleration coefficient. Higher values mean faster acceleration. + public float Acceleration; + /// The acceleration coefficient in air. Higher values mean faster acceleration. + public float AirAcceleration; + /// The friction coefficient. Higher values mean faster slowdown, should be less than or equal to Acceleration. + public float Friction; + /// The friction coefficient in air. Higher values mean faster slowdown, should be less than or equal to Acceleration. + public float AirFriction; + /// The velocity that the player jumps in this style. + public float JumpVelocity; + /// Degrees that the player leans when moving sideways in this style. + public float LeanDegrees; + } +} diff --git a/Assets/Scripts/Player/MoveStyle.cs.meta b/Assets/Scripts/Player/MoveStyle.cs.meta new file mode 100644 index 0000000..3b06d7b --- /dev/null +++ b/Assets/Scripts/Player/MoveStyle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c7827ce96d9ff12458f0de236abbab9b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/Player.cs b/Assets/Scripts/Player/Player.cs new file mode 100644 index 0000000..cecc338 --- /dev/null +++ b/Assets/Scripts/Player/Player.cs @@ -0,0 +1,132 @@ +using UnityEngine; + +namespace NeonTea.Quakeball.Player { + /// The central glue class for players (both local and remote). + /// Other classes will handle netcode/inputs, and then speak to this class in order to make the little people run around. + [RequireComponent(typeof(CharacterController))] + public class Player : MonoBehaviour { + + /// How long after running off a cliff should the player be considered "on ground"? + public float CoyoteTime; + + public MoveStyle RunningMoveStyle; + public MoveStyle CrouchingMoveStyle; + public Transform Head; + public Transform Body; + + [Header("Player rotation status")] + /// The pitch of the player's head. + public float Pitch; + /// The total yaw of the player. Head yaw is Yaw - BodyYaw. + public float Yaw; + /// The yaw of the player body. Calculated from MoveDirection. + public float BodyYaw; + + [Header("Player movement status")] + /// The direction the player is going. + public Vector3 MoveDirection; + + /// The player's desire to jump currently. + public bool Jumping; + + /// The amount of movement the player wants to happen. + /// Without analog controls, always 0 or 1. + public float InputSpeed; + + /// The way the player is moving. + public MoveStyle MoveStyle; + + [Header("Runtime computed values")] + /// The speed at which the player is currently moving across the ground. + public Vector3 GroundVelocity; + + /// The speed at which the player is rising or falling. + public Vector3 GravitationalVelocity; + + /// The timestamp of when the player was last on the ground. + public float GroundedTime; + + [Header("Misc. technical knobs")] + public float GroundCastLength = 0.2f; + public LayerMask GroundLayer; + + [Header("Debug settings")] + public bool ShowGroundCast; + + private CharacterController CharacterController; + private Vector3 FeetPosition; + + /// The normal of the ground below the player. If there is no ground, it's Vector3.up by default. + public Vector3 GroundCast() { + RaycastHit Hit; + if (ShowGroundCast) { + Debug.DrawLine(FeetPosition, FeetPosition - Vector3.up, Color.red, 1f); + } + if (Physics.Raycast(FeetPosition, -Vector3.up, out Hit, GroundCastLength, GroundLayer)) { + return Hit.normal; + } else { + return Vector3.up; + } + } + + public bool IsGrounded() { + return Time.time - GroundedTime <= CoyoteTime && Vector3.Dot(GravitationalVelocity, Vector3.down) >= 0; + } + + private void Awake() { + CharacterController = GetComponent(); + FeetPosition = transform.position + CharacterController.center - Vector3.up * (CharacterController.height / 2 + CharacterController.skinWidth / 2); + } + + private void Update() { + if (MoveDirection.magnitude > 0) { + BodyYaw = Vector3.SignedAngle(Vector3.forward, MoveDirection, Vector3.up); + } + Body.localRotation = Quaternion.Lerp(Body.localRotation, Quaternion.Euler(0, BodyYaw, 0), 20f * Time.deltaTime); + Head.localRotation = Quaternion.Lerp(Head.localRotation, Quaternion.Euler(Pitch, Yaw - BodyYaw, 0), 15f * Time.deltaTime); + UpdateMovement(); + } + + private void UpdateMovement() { + bool Grounded = IsGrounded(); + + if (Grounded) { + if (Vector3.Dot(Vector3.down, GravitationalVelocity) > 0) { + GravitationalVelocity = Vector3.zero; + } + if (Jumping) { + GravitationalVelocity = Vector3.up * MoveStyle.JumpVelocity; + } + } else { + GravitationalVelocity += Physics.gravity * Time.deltaTime; + } + + float FrictionVelocityFactor = Mathf.Max(GroundVelocity.magnitude, MoveStyle.StopVelocity); + float Deccel = FrictionVelocityFactor * Time.deltaTime; + if (Grounded) { + Deccel *= MoveStyle.Friction; + } else { + Deccel *= MoveStyle.AirFriction; + } + float FrictionedVelocity = Mathf.Max(0, GroundVelocity.magnitude - Deccel); + GroundVelocity = GroundVelocity.normalized * FrictionedVelocity; + + Vector3 GroundNormal = GroundCast(); + Vector3 FixedHeading = Vector3.ProjectOnPlane(MoveDirection, GroundNormal).normalized; + float CurrentSpeed = Vector3.Dot(GroundVelocity, FixedHeading); + float Acceleration = MoveStyle.TargetVelocity * Time.deltaTime; + if (Grounded) { + Acceleration *= MoveStyle.Acceleration; + } else { + Acceleration *= MoveStyle.AirAcceleration; + } + Acceleration = Mathf.Min(Acceleration, MoveStyle.TargetVelocity - CurrentSpeed); + GroundVelocity += FixedHeading * Acceleration; + + CharacterController.Move((GroundVelocity + GravitationalVelocity) * Time.deltaTime); + if (CharacterController.isGrounded) { + GroundedTime = Time.time; + } + } + } +} diff --git a/Assets/Scripts/Player/Player.cs.meta b/Assets/Scripts/Player/Player.cs.meta new file mode 100644 index 0000000..98ee946 --- /dev/null +++ b/Assets/Scripts/Player/Player.cs.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 40221663adaa8b54cb9b9f81042bd6b3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - RunningMoveStyle: {fileID: 11400000, guid: 550df8ac62d76a64a8c621ea6b32398f, type: 2} + - CrouchingMoveStyle: {fileID: 11400000, guid: 2d9739d3745581a41ae0ed6a569766d5, type: 2} + - Head: {instanceID: 0} + - MoveStyle: {instanceID: 0} + executionOrder: 5 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index cdc1f3e..a1242bf 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: -20, 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 diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1c92a78..516f025 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -13,9 +13,9 @@ TagManager: - UI - - - - - - - - + - CollidableEnvironment + - BulletHitLayer + - InvisibleToPlayerCamera - - -