Commit 9b087dfd authored by Jordan B Mckenney's avatar Jordan B Mckenney

commit

parent 50916e2f
fileFormatVersion: 2
guid: 2fa9369d1e9167a4597f284fdd394333
timeCreated: 1488500783
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b7c614524ded8d449a0e9a69feb4809c
timeCreated: 1488500783
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 8cc875501d3e3194eb13415523af8b1f
timeCreated: 1488500783
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -11,6 +11,7 @@ public class Walk : AbstractBehavior {
private float xScale;
public float realSpeed;
public bool wallSliding = false;
private int rightInt = 0;
private int leftInt = 0;
......@@ -31,9 +32,7 @@ public class Walk : AbstractBehavior {
rightInt = 0;
leftInt = 0;
rightTime = inputState.GetButtonHoldTime(right);
leftTime = inputState.GetButtonHoldTime(left);
if (inputState.GetButtonValue(right))
rightInt = 1;
else
......@@ -46,6 +45,7 @@ public class Walk : AbstractBehavior {
if (collisionState.onGround) //movement on ground
{
Debug.Log("on ground");
realSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
{
......@@ -62,8 +62,12 @@ public class Walk : AbstractBehavior {
}
}
body.velocity = new Vector2(realSpeed, body.velocity.y);
} else if (!collisionState.onWall)
} else if (!wallSliding) //in air and not sliding
{
if (collisionState.onWall && (inputState.GetButtonValue(right) || inputState.GetButtonValue(left)))
wallSliding = true;
Debug.Log("not on wall");
airSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
{
......@@ -81,27 +85,32 @@ public class Walk : AbstractBehavior {
}
else
{
if (airSpeed != 0) {
if (airSpeed != 0)
{
airSpeed += (-1) * Mathf.Sign(airSpeed) * airAcceleration;
if (Mathf.Abs(airSpeed) < airAcceleration)
airSpeed = 0;
}
}
body.velocity = new Vector2(airSpeed, body.velocity.y);
} else //handles on the wall
} else //handles wall sliding
{
rightTime = inputState.GetButtonHoldTime(right);
leftTime = inputState.GetButtonHoldTime(left);
Debug.Log("on wall");
airSpeed = body.velocity.x;
//only sets a change if the button has been held for a set time
if (rightTime >= wallClingTime)
{
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt), -speed, speed);
wallSliding = false;
}
if (leftTime >= wallClingTime)
{
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (leftInt), -speed, speed);
wallSliding = false;
}
/***
//same as if not on wall and not pressing the buttons
if (!inputState.GetButtonValue(right) && !inputState.GetButtonValue(left))
{
......@@ -113,6 +122,7 @@ public class Walk : AbstractBehavior {
}
}
body.velocity = new Vector2(airSpeed, body.velocity.y);
***/
}
//change localScale depending on direction
......
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