starting all this shit over

master
Jordan Orelli 5 years ago
parent 5f4df62417
commit b9240c35b8

@ -1,162 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &354415133234764730
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 354415133234764729}
- component: {fileID: 354415133234764727}
- component: {fileID: 354415133234764728}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &354415133234764729
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 354415133234764730}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 2, z: 1}
m_Children: []
m_Father: {fileID: 354415133841177158}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &354415133234764727
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 354415133234764730}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &354415133234764728
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 354415133234764730}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!1 &354415133841177159
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 354415133841177158}
- component: {fileID: 354415133841177157}
- component: {fileID: 354415133841177156}
- component: {fileID: 354415133841177155}
m_Layer: 0
m_Name: Player
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &354415133841177158
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 354415133841177159}
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:
- {fileID: 354415133234764729}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &354415133841177157
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 354415133841177159}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6e86ea0dadc883746820f81edbde5cab, type: 3}
m_Name:
m_EditorClassIdentifier:
jumpHeight: 5
jumpDuration: 0.4
moveSpeed: 6
accelerationTimeAirborne: 0.1
accelerationTimeGrounded: 0.05
--- !u!114 &354415133841177156
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 354415133841177159}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5b21a38e98a85794b9312e3ac293ad9f, type: 3}
m_Name:
m_EditorClassIdentifier:
collisionMask:
serializedVersion: 2
m_Bits: 1024
horizontalRayCount: 4
verticalRayCount: 4
maxClimbAngle: 60
maxDescendAngle: 75
--- !u!65 &354415133841177155
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 354415133841177159}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 2, z: 1}
m_Center: {x: 0, y: 0, z: 0}

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: b29a944aaba25f643afdc6b049845662
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -54,7 +54,7 @@ LightmapSettings:
m_EnableBakedLightmaps: 0 m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0 m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings: m_LightmapEditorSettings:
serializedVersion: 10 serializedVersion: 12
m_Resolution: 2 m_Resolution: 2
m_BakeResolution: 40 m_BakeResolution: 40
m_AtlasSize: 1024 m_AtlasSize: 1024
@ -62,6 +62,7 @@ LightmapSettings:
m_AOMaxDistance: 1 m_AOMaxDistance: 1
m_CompAOExponent: 1 m_CompAOExponent: 1
m_CompAOExponentDirect: 0 m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2 m_Padding: 2
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1 m_LightmapsBakeMode: 1
@ -76,10 +77,16 @@ LightmapSettings:
m_PVRDirectSampleCount: 32 m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500 m_PVRSampleCount: 500
m_PVRBounces: 2 m_PVRBounces: 2
m_PVREnvironmentSampleCount: 500
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 2
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 0
m_PVRFilterTypeDirect: 0 m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0 m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0 m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1 m_PVREnvironmentMIS: 0
m_PVRCulling: 1 m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1 m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5 m_PVRFilteringGaussRadiusIndirect: 5
@ -87,7 +94,9 @@ LightmapSettings:
m_PVRFilteringAtrousPositionSigmaDirect: 0.5 m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2 m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1 m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1 m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0} m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1 m_UseShadowmask: 1
--- !u!196 &4 --- !u!196 &4
@ -157,7 +166,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 38ce055dcd672554fae2b0acd2ca4761, type: 3} m_Script: {fileID: 11500000, guid: 38ce055dcd672554fae2b0acd2ca4761, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
player: {fileID: 1816857705} player: {fileID: 0}
--- !u!20 &519420031 --- !u!20 &519420031
Camera: Camera:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -170,9 +179,10 @@ Camera:
m_ClearFlags: 2 m_ClearFlags: 2
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1 m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24} m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0} m_LensShift: {x: 0, y: 0}
m_GateFitMode: 2
m_FocalLength: 50 m_FocalLength: 50
m_NormalizedViewPortRect: m_NormalizedViewPortRect:
serializedVersion: 2 serializedVersion: 2
@ -289,6 +299,125 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 3004802641261297316} m_PrefabInstance: {fileID: 3004802641261297316}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &937432970
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 937432976}
- component: {fileID: 937432975}
- component: {fileID: 937432974}
- component: {fileID: 937432973}
- component: {fileID: 937432972}
- component: {fileID: 937432971}
m_Layer: 8
m_Name: Player
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &937432971
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 937432970}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6e86ea0dadc883746820f81edbde5cab, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &937432972
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 937432970}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5b21a38e98a85794b9312e3ac293ad9f, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!65 &937432973
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 937432970}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 0}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &937432974
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 937432970}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &937432975
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 937432970}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &937432976
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 937432970}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 2, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &957476665 --- !u!1001 &957476665
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -383,12 +512,14 @@ Light:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1327270570} m_GameObject: {fileID: 1327270570}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 8 serializedVersion: 10
m_Type: 1 m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1 m_Intensity: 1
m_Range: 10 m_Range: 10
m_SpotAngle: 30 m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10 m_CookieSize: 10
m_Shadows: m_Shadows:
m_Type: 0 m_Type: 0
@ -398,6 +529,24 @@ Light:
m_Bias: 0.05 m_Bias: 0.05
m_NormalBias: 0.4 m_NormalBias: 0.4
m_NearPlane: 0.2 m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0} m_Cookie: {fileID: 0}
m_DrawHalo: 0 m_DrawHalo: 0
m_Flare: {fileID: 0} m_Flare: {fileID: 0}
@ -405,12 +554,15 @@ Light:
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295 m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4 m_Lightmapping: 4
m_LightShadowCasterMode: 0 m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1} m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1 m_BounceIntensity: 1
m_ColorTemperature: 6570 m_ColorTemperature: 6570
m_UseColorTemperature: 0 m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0 m_ShadowRadius: 0
m_ShadowAngle: 0 m_ShadowAngle: 0
--- !u!4 &1327270572 --- !u!4 &1327270572
@ -425,7 +577,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!4 &1337047246 stripped --- !u!4 &1337047246 stripped
Transform: Transform:
@ -433,12 +585,6 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 957476665} m_PrefabInstance: {fileID: 957476665}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!4 &1816857705 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
m_PrefabInstance: {fileID: 354415134315853359}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2094910950 --- !u!1 &2094910950
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -470,77 +616,8 @@ Transform:
- {fileID: 209604418} - {fileID: 209604418}
- {fileID: 1337047246} - {fileID: 1337047246}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 2 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &354415134315853359
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 354415133841177159, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_Name
value: Player
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 354415133841177158, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b29a944aaba25f643afdc6b049845662, type: 3}
--- !u!1001 &3004802641261297316 --- !u!1001 &3004802641261297316
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

@ -2,252 +2,63 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
[RequireComponent(typeof(BoxCollider))] // MoveController controls movement for 2D characters
[RequireComponent(typeof(BoxCollider2D))]
public class MoveController : MonoBehaviour public class MoveController : MonoBehaviour
{ {
public LayerMask collisionMask; const float skinWidth = 0.015f;
public const float skinWidth = 0.015f;
public int horizontalRayCount = 4; public int horizontalRayCount = 4;
public int verticalRayCount = 4; public int verticalRayCount = 4;
public CollisionInfo collisions;
public float maxClimbAngle = 60f;
public float maxDescendAngle = 75f;
new private BoxCollider collider;
private RaycastOrigins raycastOrigins;
private float horizontalRaySpacing; private float horizontalRaySpacing;
private float verticalRaySpacing; private float verticalRaySpacing;
private int frameCount;
new BoxCollider2D collider;
RaycastOrigins raycastOrigins;
void Start() { void Start() {
collider = GetComponent<BoxCollider>(); collider = GetComponent<BoxCollider2D>();
CalculateRaySpacing();
frameCount = 0;
} }
public void Move(Vector3 velocity) { void Update() {
frameCount++;
UpdateRaycastOrigins(); UpdateRaycastOrigins();
collisions.Reset(); CalculateRaySpacing();
collisions.velocityOld = velocity;
if (velocity.y < 0) {
DescendSlope(ref velocity);
}
if (velocity.x != 0) {
HorizontalCollisions(ref velocity);
}
if (velocity.y != 0) {
VerticalCollisions(ref velocity);
}
transform.Translate(velocity);
}
private void HorizontalCollisions(ref Vector3 velocity) {
float directionX = Mathf.Sign(velocity.x);
float rayLength = Mathf.Abs(velocity.x) + skinWidth;
for (int i = 0; i < horizontalRayCount; i++) {
Vector3 rayOrigin = (directionX == -1) ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight;
rayOrigin += Vector3.up * (horizontalRaySpacing * i);
RaycastHit hit;
if (!Physics.Raycast(rayOrigin, Vector3.right * directionX, out hit, rayLength, collisionMask)) {
Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.green);
continue;
}
float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
if (i == 0 && slopeAngle <= maxClimbAngle) {
// if uh we're descending a slope and encounter another slope
// actually no we're not descending a slope we're climbing the
// other one.
if (collisions.descendingSlope) {
collisions.descendingSlope = false;
velocity = collisions.velocityOld;
}
float distanceToSlopeStart = 0f;
if (slopeAngle!= collisions.slopeAngleOld) {
distanceToSlopeStart = hit.distance - skinWidth;
velocity.x -= distanceToSlopeStart * directionX;
}
ClimbSlope(ref velocity, slopeAngle);
// I do not remember why he put this back in, but this line
// causes my character to go through the floor when a slope
// meets another slope.
velocity.x += distanceToSlopeStart * directionX;
Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.magenta);
}
if (!collisions.climbingSlope || slopeAngle > maxClimbAngle) {
velocity.x = (hit.distance - skinWidth) * directionX;
rayLength = hit.distance;
if (collisions.climbingSlope) {
velocity.y = Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x);
}
Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.red);
if (directionX == -1) {
collisions.left = true;
} else {
collisions.right = true;
}
}
}
return;
}
private void VerticalCollisions(ref Vector3 velocity) {
float directionY = velocity.y > Mathf.Epsilon ? 1 : -1;
// float directionY = Mathf.Sign(velocity.y); // -1 for down, 1 for up
float rayLength = Mathf.Abs(velocity.y) + skinWidth;
bool hasHit = false;
float hitDistance = 0f;
for (int i = 0; i < verticalRayCount; i++) { for (int i = 0; i < verticalRayCount; i++) {
Vector3 rayOrigin = (directionY == -1) ? raycastOrigins.bottomLeft : raycastOrigins.topLeft; Debug.DrawRay(raycastOrigins.bottomLeft + Vector2.right * verticalRaySpacing * i, Vector2.up * -2, Color.red);
rayOrigin += Vector3.right * (verticalRaySpacing * i + velocity.x);
RaycastHit hit;
if (!Physics.Raycast(rayOrigin, Vector3.up * directionY, out hit, rayLength, collisionMask)) {
Debug.DrawRay(rayOrigin + velocity, Vector3.up * directionY * rayLength, Color.green);
continue;
}
//Debug.Log("Hit distance: " + hit.distance);
rayLength = hit.distance;
hasHit = true;
hitDistance = hit.distance;
Debug.DrawRay(rayOrigin, Vector3.up * directionY * rayLength, Color.red);
}
if (hasHit) {
// TODO: what the fuck is this 1.5f doing here
velocity.y = (hitDistance - 1.5f*skinWidth) * directionY;
if (directionY == -1) {
collisions.below = true;
} else {
collisions.above = true;
}
}
if (collisions.climbingSlope) {
velocity.x = velocity.y / Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Sign(velocity.x);
}
// checks for a change in slope while climbing a slope
if (collisions.climbingSlope) {
float directionX = Mathf.Sign(velocity.x);
rayLength = Mathf.Abs(velocity.x) + skinWidth;
Vector3 rayOrigin = (directionY == -1) ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight;
rayOrigin += (Vector3.up * velocity.y);
RaycastHit hit;
if (Physics.Raycast(rayOrigin, Vector3.right * directionX, out hit, rayLength, collisionMask)) {
float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
if (slopeAngle != collisions.slopeAngle) {
velocity.x = (hit.distance - skinWidth) * directionX;
collisions.slopeAngle = slopeAngle;
}
}
}
}
private void ClimbSlope(ref Vector3 velocity, float slopeAngle) {
float dist = Mathf.Abs(velocity.x);
float climbY = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * dist;
if (velocity.y <= climbY) {
velocity.y = climbY;
velocity.x = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * dist * Mathf.Sign(velocity.x);
collisions.below = true;
collisions.climbingSlope = true;
collisions.slopeAngle = slopeAngle;
}
}
private void DescendSlope(ref Vector3 velocity) {
float directionX = Mathf.Sign(velocity.x);
// cast a ray downwards from the trailing corner of the collider
Vector3 rayOrigin = (directionX == -1) ? raycastOrigins.bottomRight : raycastOrigins.bottomLeft;
RaycastHit hit;
if (!Physics.Raycast(rayOrigin, Vector3.down, out hit, Mathf.Infinity, collisionMask)) {
return;
}
float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
if (slopeAngle == 0 || slopeAngle > maxDescendAngle) {
return;
}
if (Mathf.Sign(hit.normal.x) != directionX) {
return;
}
if (hit.distance - skinWidth <= Mathf.Tan(slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x)) {
float moveDistance = Mathf.Abs(velocity.x);
float descendY = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * moveDistance;
velocity.x = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * moveDistance * Mathf.Sign(velocity.x);
velocity.y -= descendY;
collisions.below = true; // grounded
collisions.slopeAngle = slopeAngle;
collisions.descendingSlope = true;
} }
} }
void UpdateRaycastOrigins() { void UpdateRaycastOrigins() {
Bounds bounds = collider.bounds; Bounds bounds = collider.bounds;
float depth = (bounds.max.z + bounds.min.z) * 0.5f;
bounds.Expand(skinWidth * -2); bounds.Expand(skinWidth * -2);
raycastOrigins.bottomLeft = new Vector3(bounds.min.x, bounds.min.y, depth); raycastOrigins.bottomLeft = new Vector2(bounds.min.x, bounds.min.y);
raycastOrigins.topLeft = new Vector3(bounds.min.x, bounds.max.y, depth); raycastOrigins.bottomRight = new Vector2(bounds.max.x, bounds.min.y);
raycastOrigins.bottomRight = new Vector3(bounds.max.x, bounds.min.y, depth); raycastOrigins.topLeft = new Vector2(bounds.min.x, bounds.max.y);
raycastOrigins.topRight = new Vector3(bounds.max.x, bounds.max.y, depth); raycastOrigins.topRight = new Vector2(bounds.max.x, bounds.max.y);
} }
void CalculateRaySpacing() { void CalculateRaySpacing() {
Bounds bounds = collider.bounds; Bounds bounds = collider.bounds;
bounds.Expand(skinWidth * -2); bounds.Expand(skinWidth * -2);
if (horizontalRayCount < 2) { horizontalRayCount = 2; } if (horizontalRayCount < 2) {
if (verticalRayCount < 2) { verticalRayCount = 2; } horizontalRayCount = 2;
}
if (verticalRayCount < 2) {
verticalRayCount = 2;
}
horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1); horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1);
verticalRaySpacing = bounds.size.x / (verticalRayCount - 1); verticalRaySpacing = bounds.size.x / (verticalRayCount - 1);
} }
public bool Grounded() { return collisions.below; }
struct RaycastOrigins { struct RaycastOrigins {
public Vector3 topLeft; public Vector2 topLeft;
public Vector3 topRight; public Vector2 topRight;
public Vector3 bottomLeft; public Vector2 bottomLeft;
public Vector3 bottomRight; public Vector2 bottomRight;
}
public struct CollisionInfo {
public bool above;
public bool below;
public bool left;
public bool right;
public bool climbingSlope;
public bool descendingSlope;
public float slopeAngle;
public float slopeAngleOld;
public Vector3 velocityOld;
public void Reset() {
above = false;
below = false;
left = false;
right = false;
climbingSlope = false;
descendingSlope = false;
slopeAngleOld = slopeAngle;
slopeAngle = 0f;
}
} }
} }

@ -4,57 +4,24 @@ using UnityEngine;
[RequireComponent(typeof(MoveController))] [RequireComponent(typeof(MoveController))]
public class PlayerController : MonoBehaviour { public class PlayerController : MonoBehaviour {
public float jumpHeight = 5f;
public float jumpDuration = 0.4f;
public float moveSpeed = 6f;
public float accelerationTimeAirborne = 0.1f;
public float accelerationTimeGrounded = 0.05f;
private Vector3 velocity;
private float jumpVelocity;
private MoveController moveController; private MoveController moveController;
private float gravity;
private float moveXSmoothing;
void Start() { void Start() {
moveController = GetComponent<MoveController>(); moveController = GetComponent<MoveController>();
gravity = -(2*jumpHeight)/Mathf.Pow(jumpDuration, 2f);
jumpVelocity = Mathf.Abs(gravity) * jumpDuration;
} }
void Update() { void Update() {
if (moveController.collisions.above || moveController.collisions.below) {
velocity.y = 0;
}
if (moveController.collisions.left || moveController.collisions.right) {
velocity.x = 0;
}
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
if (Input.GetKeyDown(KeyCode.Space) && moveController.collisions.below) {
velocity.y = jumpVelocity;
}
float targetx = input.x * moveSpeed;
velocity.x = Mathf.SmoothDamp(velocity.x, targetx, ref moveXSmoothing, moveController.Grounded() ? accelerationTimeGrounded : accelerationTimeAirborne);
velocity.y += gravity * Time.deltaTime;
Debug.LogFormat("Grounded: {0}", moveController.Grounded());
moveController.Move(velocity * Time.deltaTime);
} }
void FixedUpdate() { void FixedUpdate() {
} }
void OnDestroy() { void OnDestroy() {
Debug.Log("I'm dead");
} }
void OnCollisionEnter(Collision other) { void OnCollisionEnter(Collision other) {
// Debug.LogFormat("Player collided with {0}", other);
} }
void OnTriggerEnter(Collider other) { void OnTriggerEnter(Collider other) {
// Debug.LogFormat("Player triggered other: {0}", other);
} }
} }

@ -13,7 +13,7 @@ TagManager:
- UI - UI
- -
- -
- - Player
- -
- Level - Level
- -

Loading…
Cancel
Save