slope climbing tweaks

master
Jordan Orelli 5 years ago
parent a3fc4638f7
commit 5a2314ea8c

@ -181,6 +181,97 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &185101268
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 185101272}
- component: {fileID: 185101271}
- component: {fileID: 185101270}
- component: {fileID: 185101269}
m_Layer: 11
m_Name: Cube (3)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &185101269
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 185101268}
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 &185101270
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 185101268}
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 &185101271
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 185101268}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &185101272
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 185101268}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 5.51, y: 2.63, z: 0}
m_LocalScale: {x: 0.25, y: 0.25, z: 0.25}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &240621025 --- !u!1 &240621025
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -266,12 +357,103 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 240621025} m_GameObject: {fileID: 240621025}
m_LocalRotation: {x: 0, y: 0, z: 0.27563733, w: 0.96126175} m_LocalRotation: {x: 0, y: 0, z: 0.27563733, w: 0.96126175}
m_LocalPosition: {x: 1.55, y: 0.625, z: 0} m_LocalPosition: {x: 7.41, y: 3.59, z: 0}
m_LocalScale: {x: 2, y: 0.25, z: 0.25} m_LocalScale: {x: 12.63, y: 0.25, z: 0.25}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 5 m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 32} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 32}
--- !u!1 &601208616
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 601208620}
- component: {fileID: 601208619}
- component: {fileID: 601208618}
- component: {fileID: 601208617}
m_Layer: 11
m_Name: Cube (4)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &601208617
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 601208616}
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 &601208618
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 601208616}
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 &601208619
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 601208616}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &601208620
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 601208616}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2.147, y: 1.876, z: 0}
m_LocalScale: {x: 5, y: 0.25, z: 0.25}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &1063375671 stripped --- !u!4 &1063375671 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 6383496741192187647, guid: cd445451907d7274daea79c67e13a202, m_CorrespondingSourceObject: {fileID: 6383496741192187647, guid: cd445451907d7274daea79c67e13a202,

@ -10,7 +10,7 @@ public class MoveController : MonoBehaviour
public int horizontalRayCount = 4; public int horizontalRayCount = 4;
public int verticalRayCount = 4; public int verticalRayCount = 4;
public CollisionInfo collisions; public CollisionInfo collisions;
public float maxClimbAngle = 80f; public float maxClimbAngle = 60f;
new private BoxCollider collider; new private BoxCollider collider;
private RaycastOrigins raycastOrigins; private RaycastOrigins raycastOrigins;
@ -45,7 +45,7 @@ public class MoveController : MonoBehaviour
RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.right * directionX, rayLength, collisionMask); RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.right * directionX, rayLength, collisionMask);
if (hits.Length == 0) { if (hits.Length == 0) {
Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.magenta); Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.green);
continue; continue;
} }
@ -57,20 +57,32 @@ public class MoveController : MonoBehaviour
} }
float slopeAngle = Vector3.Angle(hit.normal, Vector3.up); float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
if (i == 0) { if (i == 0 && slopeAngle <= maxClimbAngle) {
Debug.LogFormat("Slope angle: {0}", slopeAngle); float distanceToSlopeStart = 0f;
if (slopeAngle!= collisions.slopeAngleOld) {
distanceToSlopeStart = hit.distance - skinWidth;
velocity.x -= distanceToSlopeStart * directionX;
}
ClimbSlope(ref velocity, slopeAngle); ClimbSlope(ref velocity, slopeAngle);
velocity.x += distanceToSlopeStart * directionX;
Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.magenta);
} }
velocity.x = (hit.distance - skinWidth) * directionX; if (!collisions.climbingSlope || slopeAngle > maxClimbAngle) {
// Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, hit.distance, velocity.y); velocity.x = (hit.distance - skinWidth) * directionX;
rayLength = hit.distance; rayLength = hit.distance;
Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.red);
if (directionX == -1) { if (collisions.climbingSlope) {
collisions.left = true; velocity.y = Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x);
} else { }
collisions.right = true;
Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.red);
if (directionX == -1) {
collisions.left = true;
} else {
collisions.right = true;
}
} }
} }
} }
@ -97,6 +109,10 @@ public class MoveController : MonoBehaviour
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); // 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) {
velocity.x = velocity.y / Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Sign(velocity.x);
}
Debug.DrawRay(rayOrigin + velocity, Vector3.up * directionY * rayLength, Color.red); Debug.DrawRay(rayOrigin + velocity, Vector3.up * directionY * rayLength, Color.red);
if (directionY == -1) { if (directionY == -1) {
@ -109,8 +125,14 @@ public class MoveController : MonoBehaviour
private void ClimbSlope(ref Vector3 velocity, float slopeAngle) { private void ClimbSlope(ref Vector3 velocity, float slopeAngle) {
float dist = Mathf.Abs(velocity.x); float dist = Mathf.Abs(velocity.x);
velocity.y = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * dist; float climbY = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * dist;
velocity.x = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * dist * Mathf.Sign(velocity.x); 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;
}
} }
void UpdateRaycastOrigins() { void UpdateRaycastOrigins() {
@ -149,7 +171,18 @@ public class MoveController : MonoBehaviour
public bool below; public bool below;
public bool left; public bool left;
public bool right; public bool right;
public bool climbingSlope;
public void Reset() { above = below = left = right = false; } public float slopeAngle;
public float slopeAngleOld;
public void Reset() {
above = false;
below = false;
left = false;
right = false;
climbingSlope = false;
slopeAngleOld = slopeAngle;
slopeAngle = 0f;
}
} }
} }

Loading…
Cancel
Save