Commit 222a2258 authored by Tanner Grehawick's avatar Tanner Grehawick

fixed jitter when wall sliding across seam

parent 46c0d8b4
......@@ -3045,6 +3045,16 @@ Prefab:
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 114757865948649954, guid: dfa71b7b6162c694ab929717dd70b38d,
type: 2}
propertyPath: skinWidth
value: 0.05
objectReference: {fileID: 0}
- target: {fileID: 114757865948649954, guid: dfa71b7b6162c694ab929717dd70b38d,
type: 2}
propertyPath: wallCheckDistance
value: 0.1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: dfa71b7b6162c694ab929717dd70b38d, type: 2}
m_IsPrefabParent: 0
......@@ -3363,6 +3373,85 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1194382622
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1194382625}
- component: {fileID: 1194382624}
- component: {fileID: 1194382623}
m_Layer: 0
m_Name: Solid (3)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!61 &1194382623
BoxCollider2D:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1194382622}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Size: {x: 1, y: 1.0000001}
--- !u!212 &1194382624
SpriteRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1194382622}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_MotionVectors: 1
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
m_Materials:
- {fileID: 10754, 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_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: -275913165
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 09c56331da3a32645bf0d09dc376f76c, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
--- !u!4 &1194382625
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1194382622}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -5.52, y: 2, z: 0}
m_LocalScale: {x: 4.7093396, y: 3, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1373822964
GameObject:
m_ObjectHideFlags: 0
......@@ -3683,8 +3772,8 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1774567343}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -5.52, y: 0.2, z: 0}
m_LocalScale: {x: 4.7093396, y: 7.164482, z: 1}
m_LocalPosition: {x: -5.52, y: -1, z: 0}
m_LocalScale: {x: 4.7093396, y: 3, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
......
......@@ -7,6 +7,7 @@ public class CollisionState : MonoBehaviour {
public LayerMask enemyLayer;
public float skinWidth = 0;
public float groundCheckDistance = 0.1f;
public float wallCheckDistance = 0.1f;
public bool onGround { get; private set; }
public bool onWallLeft { get; private set; }
......@@ -37,46 +38,50 @@ public class CollisionState : MonoBehaviour {
void FixedUpdate() {
// TODO: enemy hit stuff
RaycastHit2D hit;
onGround = CheckCollision(Vector2.down, groundCheckDistance);
onWallLeft = CheckCollision(Vector2.left, wallCheckDistance);
onWallRight = CheckCollision(Vector2.right, wallCheckDistance);
}
RaycastHit2D hit = Physics2D.CircleCast(
circle.bounds.center, // center
circle.radius - skinWidth, // radius
Vector2.down, // direction
groundCheckDistance, // distance
collisionLayer // layermask
);
onGround = hit.collider != null;
bool CheckCollision(Vector2 direction, float range) {
return Physics2D.CircleCast(
circle.bounds.center, // center
circle.radius - skinWidth, // radius
direction, // direction
range, // distance
collisionLayer // layermask
).collider != null;
}
float lastFixedTime;
void OnCollisionStay2D(Collision2D collision) {
if (Time.fixedTime != lastFixedTime) {
// only reset flags at the start of each frame
// (OnCollisionStay2D is called once for every collider this body is in contact with)
onWallLeft = false;
onWallRight = false;
lastFixedTime = Time.fixedTime;
}
foreach (ContactPoint2D contact in collision.contacts) {
Color color = Color.white;
Vector2 normal = contact.normal;
if (normal == Vector2.right) {
color = Color.red;
onWallLeft = true;
}
if (normal == -Vector2.right) {
color = Color.green;
onWallRight = true;
}
Debug.DrawRay(contact.point, contact.normal, color);
}
}
// void OnCollisionStay2D(Collision2D collision) {
// if (Time.fixedTime != lastFixedTime) {
// // only reset flags at the start of each frame
// // (OnCollisionStay2D is called once for every collider this body is in contact with)
// onWallLeft = false;
// onWallRight = false;
// lastFixedTime = Time.fixedTime;
// }
// foreach (ContactPoint2D contact in collision.contacts) {
// Color color = Color.white;
// Vector2 normal = contact.normal;
// if (normal == Vector2.right) {
// color = Color.red;
// onWallLeft = true;
// }
// if (normal == -Vector2.right) {
// color = Color.green;
// onWallRight = true;
// }
// Debug.DrawRay(contact.point, contact.normal, color);
// }
// }
void OnCollisionExit2D() {
// reset flags when we arent colliding with anything at all
onWallLeft = false;
onWallRight = false;
}
// void OnCollisionExit2D() {
// // reset flags when we arent colliding with anything at all
// onWallLeft = false;
// onWallRight = false;
// }
}
......@@ -136,7 +136,7 @@ public class Walk : AbstractBehavior {
//slow down y velocity
if(body.velocity.y < clingSpeed)
{
body.velocity = new Vector2(body.velocity.x, -clingSpeed);
body.velocity = new Vector2(0, -clingSpeed);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment