Commit b4ddfc3f authored by Tanner Grehawick's avatar Tanner Grehawick

Merge branch 'character-wallslide-fix'

parents 92196c35 46c0d8b4
......@@ -17,7 +17,6 @@ ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
......
{
"files.exclude":
{
"**/.DS_Store":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
}
}
\ No newline at end of file
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": /*"C:\\Windows\\System32\\net.exe", //*/"dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ ],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
]
}
\ No newline at end of file
fileFormatVersion: 2
<<<<<<< HEAD
guid: d6cfe212a9e97a048bc05857f0f87591
folderAsset: yes
timeCreated: 1490918387
=======
guid: 6b0486f30d6e140c8817042ff4497ea2
folderAsset: yes
timeCreated: 1490918160
>>>>>>> character-wallslide-fix
licenseType: Free
DefaultImporter:
userData:
......
fileFormatVersion: 2
<<<<<<< HEAD
guid: 2aab0f924f5a7d14a927cf6163be748a
timeCreated: 1490918393
=======
guid: cf0e3c557f3e34755841560ab8675f13
timeCreated: 1490918165
>>>>>>> character-wallslide-fix
licenseType: Free
NativeFormatImporter:
userData:
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1583886293531340}
m_IsPrefabParent: 1
--- !u!1 &1566234127395496
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4985997972421274}
m_Layer: 0
m_Name: RightCheck
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1583886293531340
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4853129226590082}
- component: {fileID: 212141967522432748}
- component: {fileID: 61263212704667228}
- component: {fileID: 50274507472267336}
- component: {fileID: 114972437443671610}
- component: {fileID: 114616278387452732}
m_Layer: 0
m_Name: VerticalEnemy
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1730385478065064
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4110681633737894}
m_Layer: 0
m_Name: LeftCheck
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4110681633737894
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1730385478065064}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.067, y: -0.067, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4853129226590082}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4853129226590082
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1583886293531340}
m_LocalRotation: {x: 0, y: 0, z: 0.7071068, w: 0.7071068}
m_LocalPosition: {x: -0.263, y: -2.08, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4985997972421274}
- {fileID: 4110681633737894}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 90}
--- !u!4 &4985997972421274
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1566234127395496}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.061, y: -0.068, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4853129226590082}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &50274507472267336
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1583886293531340}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 4
--- !u!61 &61263212704667228
BoxCollider2D:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1583886293531340}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_Offset: {x: 0.0006945133, y: 0.00000023841858}
serializedVersion: 2
m_Size: {x: 0.13083193, y: 0.134999}
--- !u!114 &114616278387452732
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1583886293531340}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 763513e1173772545a16c3cb1a4d40d5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &114972437443671610
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1583886293531340}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 05dbd03edc2481241a4f4323cee9a2a6, type: 3}
m_Name:
m_EditorClassIdentifier:
speed: 2
maxMoveDistance: 0.5
rightCollisionPos: {fileID: 4985997972421274}
leftCollisionPos: {fileID: 4110681633737894}
hasEnteredView: 0
leftWall: 0
--- !u!212 &212141967522432748
SpriteRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1583886293531340}
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: 0
m_SortingOrder: 0
m_Sprite: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
fileFormatVersion: 2
guid: 4a2a07969139f4460a11b4b64571647f
timeCreated: 1490918165
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -33,6 +33,10 @@ public class Jump : AbstractBehavior {
}
jumpState = Mathf.Sqrt(jumpState);
animator.SetFloat("jump state", jumpState);
// reset air jumps when on ground
if (collisionState.onGround) {
airJumpsMade = 0;
}
}
void FixedUpdate() {
......@@ -46,7 +50,6 @@ public class Jump : AbstractBehavior {
public void Activate() {
if (collisionState.onGround) {
// ground jump
airJumpsMade = 0;
Vector2 vel = body.velocity;
vel.y = GetJumpVelocity(jumpHeight);
body.velocity = vel;
......
......@@ -5,22 +5,29 @@ public class CollisionState : MonoBehaviour {
public LayerMask collisionLayer;
public LayerMask enemyLayer;
public bool onGround, onWall, onWallRight, onWallLeft;
public Vector2 bottomPosition = Vector2.zero;
public Vector2 rightPosition = Vector2.zero;
public Vector2 leftPosition = Vector2.zero;
public float collisionRadius = 1f;
public float skinWidth = 0;
public float groundCheckDistance = 0.1f;
[HideInInspector]public Collider2D enemyHit;
public bool onGround { get; private set; }
public bool onWallLeft { get; private set; }
public bool onWallRight { get; private set; }
public bool onWall {
get {
return onWallLeft || onWallRight;
}
}
private InputState inputState;
private Rigidbody2D body;
private Animator animator;
private CircleCollider2D circle;
void Awake() {
inputState = GetComponent<InputState>();
body = GetComponent<Rigidbody2D>();
animator = GetComponentInChildren<Animator>();
circle = GetComponent<CircleCollider2D>();
}
void Update() {
......@@ -29,46 +36,25 @@ public class CollisionState : MonoBehaviour {
}
void FixedUpdate() {
// TODO: enemy hit stuff
RaycastHit2D hit = Physics2D.CircleCast(
circle.bounds.center, // center
circle.radius - skinWidth, // radius
Vector2.down, // direction
groundCheckDistance, // distance
collisionLayer // layermask
);
onGround = hit.collider != null;
enemyHit = null;
// onGround = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, collisionLayer);
// onWallLeft = Physics2D.OverlapCircle(body.position + leftPosition, collisionRadius, collisionLayer);
// onWallRight = Physics2D.OverlapCircle(body.position + rightPosition, collisionRadius, collisionLayer);
// onWall = onWallRight || onWallLeft;
enemyHit = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, enemyLayer);
}
// void OnDrawGizmosSelected() {
// Gizmos.color = Color.red;
// Vector2 pos = bottomPosition;
// pos.x += transform.position.x;
// pos.y += transform.position.y;
// Gizmos.DrawWireSphere(pos, collisionRadius);
// pos = rightPosition;
// pos.x += transform.position.x;
// pos.y += transform.position.y;
// Gizmos.DrawWireSphere(pos, collisionRadius);
// pos = leftPosition;
// pos.x += transform.position.x;
// pos.y += transform.position.y;
// Gizmos.DrawWireSphere(pos, collisionRadius);
// }
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)
onGround = false;
onWallLeft = false;
onWallRight = false;
lastFixedTime = Time.fixedTime;
......@@ -84,20 +70,13 @@ public class CollisionState : MonoBehaviour {
color = Color.green;
onWallRight = true;
}
if (normal == Vector2.up) {
color = Color.blue;
onGround = true;
}
onWall = onWallLeft || onWallRight;
Debug.DrawRay(contact.point, contact.normal, color);
}
}
void OnCollisionExit2D() {
// reset flags when we arent colliding with anything at all
onGround = false;
onWallLeft = false;
onWallRight = false;
onWall = false;
}
}
......@@ -7,7 +7,7 @@ public class Walk : AbstractBehavior {
private float airSpeed;
public float airAcceleration;
public float friction;
public float wallClingTime; //time you will 'stick' to the wall after pressing the opposite direction
public float wallClingTime; //time you will 'stick' to the wall after releasing slide button
public float clingSpeed = 0.1f;
public float realSpeed;
......@@ -45,7 +45,6 @@ public class Walk : AbstractBehavior {
else
leftInt = 0;
isWallSliding = false;
if (collisionState.onGround) //movement on ground
{
......@@ -99,40 +98,46 @@ public class Walk : AbstractBehavior {
body.velocity = new Vector2(airSpeed, body.velocity.y);
} else //handles wall sliding
{
isWallSliding = true;
rightTime = inputState.GetButtonHoldTime(right);
leftTime = inputState.GetButtonHoldTime(left);
isWallSliding =
(collisionState.onWallLeft && inputState.GetButtonValue(left)) ||
(collisionState.onWallRight && inputState.GetButtonValue(right));
airSpeed = body.velocity.x;
if (isWallSliding) {
//only sets a change if the button has been held for a set time
if (rightTime >= wallClingTime && collisionState.onWallLeft)
{
isWallSliding = false;
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
}
if (leftTime >= wallClingTime && collisionState.onWallRight)
{
isWallSliding = false;
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
}
/*
airSpeed = body.velocity.x;
//same as if not on wall and not pressing the buttons
if (!inputState.GetButtonValue(right) && !inputState.GetButtonValue(left))
{
if (airSpeed != 0)
//only sets a change if the button has been held for a set time
if (rightTime >= wallClingTime && collisionState.onWallLeft)
{
airSpeed += (-1) * Mathf.Sign(airSpeed) * airAcceleration;
if (Mathf.Abs(airSpeed) < airAcceleration)
airSpeed = 0;
isWallSliding = false;
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
}
if (leftTime >= wallClingTime && collisionState.onWallRight)
{
isWallSliding = false;
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
}
*/
//same as if not on wall and not pressing the buttons
// if (!inputState.GetButtonValue(right) && !inputState.GetButtonValue(left))
// {
// if (airSpeed != 0)
// {
// airSpeed += (-1) * Mathf.Sign(airSpeed) * airAcceleration;
// if (Mathf.Abs(airSpeed) < airAcceleration)
// airSpeed = 0;
// }
// }
// body.velocity = new Vector2(airSpeed, body.velocity.y);
//slow down y velocity
if(body.velocity.y < clingSpeed)
{
body.velocity = new Vector2(body.velocity.x, -clingSpeed);
}
}
body.velocity = new Vector2(airSpeed, body.velocity.y);
//slow down y velocity
if(body.velocity.y < clingSpeed)
{
body.velocity = new Vector2(body.velocity.x, -clingSpeed);
}
}
......
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2008
Project("{5DD3948C-2617-5AAA-0728-B105EE408BCA}") = "birb", "Assembly-CSharp.csproj", "{1E11D225-4342-53A9-FFB9-C7C08411E597}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1E11D225-4342-53A9-FFB9-C7C08411E597}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E11D225-4342-53A9-FFB9-C7C08411E597}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E11D225-4342-53A9-FFB9-C7C08411E597}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E11D225-4342-53A9-FFB9-C7C08411E597}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Assembly-CSharp.csproj
EndGlobalSection
EndGlobal
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