can now land on slopes without falling through them

master
Jordan Orelli 5 years ago
parent fbc72df7b4
commit c8d69484e6

@ -2062,6 +2062,97 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 1083866099} m_PrefabInstance: {fileID: 1083866099}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &383224686
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 383224690}
- component: {fileID: 383224689}
- component: {fileID: 383224688}
- component: {fileID: 383224687}
m_Layer: 11
m_Name: Cube (7)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &383224687
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 383224686}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &383224688
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 383224686}
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: 2100000, guid: 25b52a028a50a694e898d82345ba62dc, type: 2}
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!33 &383224689
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 383224686}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &383224690
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 383224686}
m_LocalRotation: {x: 0, y: 0, z: -0.37897158, w: 0.9254083}
m_LocalPosition: {x: -14.09, y: 6.37, z: 0}
m_LocalScale: {x: 9.08, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: 0, y: 0, z: -44.54}
--- !u!4 &387153462 stripped --- !u!4 &387153462 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 7525036764583245661, guid: f97b2236cb22fbc46a20b65f13071959, m_CorrespondingSourceObject: {fileID: 7525036764583245661, guid: f97b2236cb22fbc46a20b65f13071959,
@ -2378,7 +2469,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: 14 m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &428174253 stripped --- !u!4 &428174253 stripped
Transform: Transform:
@ -8089,6 +8180,97 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
deadText: {fileID: 1820516943} deadText: {fileID: 1820516943}
--- !u!1 &1539045731
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1539045735}
- component: {fileID: 1539045734}
- component: {fileID: 1539045733}
- component: {fileID: 1539045732}
m_Layer: 11
m_Name: Cube (6)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &1539045732
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1539045731}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1539045733
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1539045731}
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: 2100000, guid: 25b52a028a50a694e898d82345ba62dc, type: 2}
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!33 &1539045734
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1539045731}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1539045735
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1539045731}
m_LocalRotation: {x: 0, y: 0, z: -0.18137747, w: 0.9834136}
m_LocalPosition: {x: -6.64, y: 1.58, z: 0}
m_LocalScale: {x: 9.08, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: -20.9}
--- !u!1001 &1550689737 --- !u!1001 &1550689737
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -9001,6 +9183,97 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f97b2236cb22fbc46a20b65f13071959, type: 3} m_SourcePrefab: {fileID: 100100000, guid: f97b2236cb22fbc46a20b65f13071959, type: 3}
--- !u!1 &1726297480
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1726297484}
- component: {fileID: 1726297483}
- component: {fileID: 1726297482}
- component: {fileID: 1726297481}
m_Layer: 11
m_Name: Cube (5)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &1726297481
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1726297480}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1726297482
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1726297480}
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: 2100000, guid: 25b52a028a50a694e898d82345ba62dc, type: 2}
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!33 &1726297483
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1726297480}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1726297484
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1726297480}
m_LocalRotation: {x: 0, y: 0, z: 0.2588191, w: 0.9659258}
m_LocalPosition: {x: 20.74, y: 6.48, z: 0}
m_LocalScale: {x: 5, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 30}
--- !u!4 &1738378165 stripped --- !u!4 &1738378165 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 7525036764583245661, guid: f97b2236cb22fbc46a20b65f13071959, m_CorrespondingSourceObject: {fileID: 7525036764583245661, guid: f97b2236cb22fbc46a20b65f13071959,
@ -11053,80 +11326,6 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 1410476410} m_PrefabInstance: {fileID: 1410476410}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1001 &3972122049024678981
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 923676258187016684, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_Name
value: Soul
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalPosition.x
value: 12
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalPosition.y
value: 6
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_RootOrder
value: 13
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3487225793045142114, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 945971871285315277, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}
propertyPath: playerName
value: jordanorelli
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 80b838e4e488ed64b9ac358ee000f444, type: 3}
--- !u!1001 &6383496741781373543 --- !u!1001 &6383496741781373543
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

@ -11,21 +11,30 @@ public class MoveController : MonoBehaviour
public int verticalRayCount = 4; public int verticalRayCount = 4;
public CollisionInfo collisions; public CollisionInfo collisions;
public float maxClimbAngle = 60f; public float maxClimbAngle = 60f;
public float maxDescendAngle = 75f;
new private BoxCollider collider; new private BoxCollider collider;
private RaycastOrigins raycastOrigins; private RaycastOrigins raycastOrigins;
private float horizontalRaySpacing; private float horizontalRaySpacing;
private float verticalRaySpacing; private float verticalRaySpacing;
private int frameCount;
void Start() { void Start() {
collider = GetComponent<BoxCollider>(); collider = GetComponent<BoxCollider>();
CalculateRaySpacing(); CalculateRaySpacing();
frameCount = 0;
} }
public void Move(Vector3 velocity) { public void Move(Vector3 velocity) {
frameCount++;
UpdateRaycastOrigins(); UpdateRaycastOrigins();
collisions.Reset(); collisions.Reset();
collisions.velocityOld = velocity;
// if (velocity.y < 0) {
// DescendSlope(ref velocity);
// }
if (velocity.x != 0) { if (velocity.x != 0) {
HorizontalCollisions(ref velocity); HorizontalCollisions(ref velocity);
} }
@ -36,33 +45,25 @@ public class MoveController : MonoBehaviour
} }
private void HorizontalCollisions(ref Vector3 velocity) { private void HorizontalCollisions(ref Vector3 velocity) {
float directionX = Mathf.Sign(velocity.x); // -1 for left, 1 for right float directionX = Mathf.Sign(velocity.x);
float rayLength = Mathf.Abs(velocity.x) + skinWidth; float rayLength = Mathf.Abs(velocity.x) + skinWidth;
for (int i = 0; i < horizontalRayCount; i++) { for (int i = 0; i < horizontalRayCount; i++) {
Vector3 rayOrigin = (directionX == -1) ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight; Vector3 rayOrigin = (directionX == -1) ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight;
rayOrigin += Vector3.up * (horizontalRaySpacing * i); rayOrigin += Vector3.up * (horizontalRaySpacing * i);
RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.right * directionX, rayLength, collisionMask); RaycastHit hit;
if (hits.Length == 0) { if (!Physics.Raycast(rayOrigin, Vector3.right * directionX, out hit, rayLength, collisionMask)) {
Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.green); Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.green);
continue; continue;
} }
RaycastHit hit = hits[0];
for (int h = 1; h < hits.Length; h++) {
if (hits[h].distance < hit.distance) {
hit = hits[h];
}
}
if (hit.collider.gameObject.CompareTag("Fatal")) {
Destroy(gameObject);
return;
}
float slopeAngle = Vector3.Angle(hit.normal, Vector3.up); float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
if (i == 0 && slopeAngle <= maxClimbAngle) { if (i == 0 && slopeAngle <= maxClimbAngle) {
// if (collisions.descendingSlope) {
// collisions.descendingSlope = false;
// velocity = collisions.velocityOld;
// }
float distanceToSlopeStart = 0f; float distanceToSlopeStart = 0f;
if (slopeAngle!= collisions.slopeAngleOld) { if (slopeAngle!= collisions.slopeAngleOld) {
distanceToSlopeStart = hit.distance - skinWidth; distanceToSlopeStart = hit.distance - skinWidth;
@ -99,21 +100,15 @@ public class MoveController : MonoBehaviour
for (int i = 0; i < verticalRayCount; i++) { for (int i = 0; i < verticalRayCount; i++) {
Vector3 rayOrigin = (directionY == -1) ? raycastOrigins.bottomLeft : raycastOrigins.topLeft; Vector3 rayOrigin = (directionY == -1) ? raycastOrigins.bottomLeft : raycastOrigins.topLeft;
rayOrigin += Vector3.right * (verticalRaySpacing * i); rayOrigin += Vector3.right * (verticalRaySpacing * i + velocity.x);
RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.up * directionY, rayLength, collisionMask);
if (hits.Length == 0) { RaycastHit hit;
if (!Physics.Raycast(rayOrigin, Vector3.up * directionY, out hit, rayLength, collisionMask)) {
Debug.DrawRay(rayOrigin + velocity, Vector3.up * directionY * rayLength, Color.green); Debug.DrawRay(rayOrigin + velocity, Vector3.up * directionY * rayLength, Color.green);
continue; continue;
} }
RaycastHit hit = hits[0];
for (int h = 1; h < hits.Length; h++) {
if (hits[h].distance < hit.distance) {
hit = hits[h];
}
}
velocity.y = (hit.distance - skinWidth) * directionY; velocity.y = (hit.distance - skinWidth) * directionY;
// Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, hit.distance, velocity.y);
rayLength = hit.distance; rayLength = hit.distance;
if (collisions.climbingSlope) { if (collisions.climbingSlope) {
@ -127,6 +122,21 @@ public class MoveController : MonoBehaviour
collisions.above = true; collisions.above = true;
} }
} }
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) { private void ClimbSlope(ref Vector3 velocity, float slopeAngle) {
@ -141,6 +151,52 @@ public class MoveController : MonoBehaviour
} }
} }
private void DescendSlope(ref Vector3 velocity) {
bool movingRight = velocity.x > 0;
Vector3 rayOrigin;
if (movingRight) {
rayOrigin = raycastOrigins.bottomLeft;
} else {
rayOrigin = raycastOrigins.bottomRight;
}
Debug.DrawRay(rayOrigin + velocity, Vector3.down * Mathf.Abs(velocity.y), Color.magenta);
RaycastHit hit;
if (!Physics.Raycast(rayOrigin, Vector3.down, out hit, Mathf.Abs(velocity.y)+skinWidth, collisionMask)) {
return;
}
float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
if (slopeAngle == 0 || slopeAngle > maxDescendAngle) {
return;
}
if (Mathf.Sign(hit.normal.x) != Mathf.Sign(velocity.x)) {
return;
}
Debug.LogFormat("Descending slope at angle: {0}", slopeAngle);
// float directionX = Mathf.Sign(velocity.x);
// Vector3 rayOrigin = (directionX == -1) ? raycastOrigins.bottomRight : raycastOrigins.bottomLeft;
// RaycastHit hit;
// Debug.DrawRay(rayOrigin+velocity, Vector3.down * Mathf.Infinity, Color.green);
// if (Physics.Raycast(rayOrigin, Vector3.down, out hit, Mathf.Infinity, collisionMask)) {
// float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
// if (slopeAngle != 0 && slopeAngle <= maxDescendAngle) {
// if (Mathf.Sign(hit.normal.x) == directionX) {
// if (hit.distance - skinWidth <= Mathf.Tan(slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x)) {
// Debug.LogFormat("Descending slope with angle {0} at hit distance {1}", slopeAngle, hit.distance);
// float moveDistance = Mathf.Abs(velocity.x);
// float descendVelocityY = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * moveDistance;
// velocity.x = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * moveDistance * Mathf.Sign(velocity.x);
// velocity.y -= descendVelocityY;
// collisions.slopeAngle = slopeAngle;
// collisions.descendingSlope = true;
// collisions.below = true;
// }
// }
// }
// }
}
void UpdateRaycastOrigins() { void UpdateRaycastOrigins() {
Bounds bounds = collider.bounds; Bounds bounds = collider.bounds;
float depth = (bounds.max.z + bounds.min.z) * 0.5f; float depth = (bounds.max.z + bounds.min.z) * 0.5f;
@ -178,8 +234,10 @@ public class MoveController : MonoBehaviour
public bool left; public bool left;
public bool right; public bool right;
public bool climbingSlope; public bool climbingSlope;
public bool descendingSlope;
public float slopeAngle; public float slopeAngle;
public float slopeAngleOld; public float slopeAngleOld;
public Vector3 velocityOld;
public void Reset() { public void Reset() {
above = false; above = false;
@ -187,6 +245,7 @@ public class MoveController : MonoBehaviour
left = false; left = false;
right = false; right = false;
climbingSlope = false; climbingSlope = false;
descendingSlope = false;
slopeAngleOld = slopeAngle; slopeAngleOld = slopeAngle;
slopeAngle = 0f; slopeAngle = 0f;
} }

Loading…
Cancel
Save