Commit fe91af97 authored by Tanner Grehawick's avatar Tanner Grehawick

wall sliding fixes (read body for details)

* correct inputState.direction when wall sliding
* fix isWallSliding bug when trying to move into the wall being slid on
* wall jump now checks walk.isWallSliding instead of collisionState.onWall
parent 62d5b853
......@@ -11,9 +11,14 @@ public class Jump : AbstractBehavior {
public float wallJumpHorizontalSpeed = 5;
bool jumpRequested;
int airJumpsMade = 0;
Walk walk;
protected override void Awake() {
base.Awake();
walk = GetComponent<Walk>();
}
void Update() {
if (!jumpRequested && inputState.GetButtonPressed(inputButtons[0])) {
......@@ -45,7 +50,7 @@ public class Jump : AbstractBehavior {
vel.y = GetJumpVelocity(jumpHeight);
body.velocity = vel;
}
else if (collisionState.onWall) {
else if (walk.isWallSliding) {
// wall jump
Vector2 vel = Vector2.up * GetJumpVelocity(wallJumpHeight);
if (collisionState.onWallLeft) {
......
......@@ -11,7 +11,7 @@ public class Walk : AbstractBehavior {
public float clingSpeed = 0.1f;
public float realSpeed;
public bool wallSliding = false;
public bool isWallSliding = false;
private int rightInt = 0;
private int leftInt = 0;
......@@ -21,8 +21,8 @@ public class Walk : AbstractBehavior {
void Update() {
Vector2 vel = body.velocity;
float hspeed = Mathf.Abs(vel.x / speed);
animator.SetFloat("horizontal speed", hspeed);
float wallState = Mathf.Abs(vel.x / speed);
animator.SetFloat("walk state", wallState);
}
// Update is called once per frame
......@@ -44,7 +44,7 @@ public class Walk : AbstractBehavior {
else
leftInt = 0;
wallSliding = false;
isWallSliding = false;
if (collisionState.onGround) //movement on ground
{
......@@ -65,10 +65,11 @@ public class Walk : AbstractBehavior {
}
}
body.velocity = new Vector2(realSpeed, body.velocity.y);
} else if (!collisionState.onWall || body.velocity.y > 0) //in air and not sliding
{
}
//in air and not sliding
else if (!collisionState.onWall || body.velocity.y > 0) {
wallSliding = false;
isWallSliding = false;
airSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
......@@ -97,21 +98,21 @@ public class Walk : AbstractBehavior {
body.velocity = new Vector2(airSpeed, body.velocity.y);
} else //handles wall sliding
{
wallSliding = true;
isWallSliding = true;
rightTime = inputState.GetButtonHoldTime(right);
leftTime = inputState.GetButtonHoldTime(left);
airSpeed = body.velocity.x;
//only sets a change if the button has been held for a set time
if (rightTime >= wallClingTime)
if (rightTime >= wallClingTime && collisionState.onWallLeft)
{
wallSliding = false;
isWallSliding = false;
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
}
if (leftTime >= wallClingTime)
if (leftTime >= wallClingTime && collisionState.onWallRight)
{
wallSliding = false;
isWallSliding = false;
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
}
......@@ -135,15 +136,24 @@ public class Walk : AbstractBehavior {
}
if (inputState.GetButtonValue (right) && inputState.GetButtonValue (left))
{
} else if (inputState.GetButtonValue (right))
{
inputState.direction = Directions.Right;
} else if (inputState.GetButtonValue (left))
{
inputState.direction = Directions.Left;
// update animator and direction to match velocity / wall sliding
Vector2 vel = body.velocity;
float hvel = vel.x;
if (isWallSliding) {
if (collisionState.onWallLeft) {
inputState.direction = Directions.Right;
}
else if (collisionState.onWallRight) {
inputState.direction = Directions.Left;
}
}
else {
if (hvel > 0) {
inputState.direction = Directions.Right;
}
if (hvel < 0) {
inputState.direction = Directions.Left;
}
}
}
}
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