Commit 568734b5 authored by Jordan B Mckenney's avatar Jordan B Mckenney

updated walk script

parent c6d84b14
......@@ -3,11 +3,14 @@ using System.Collections.Generic;
using UnityEngine;
public class Walk : AbstractBehavior {
public int speed;
public float speed;
private float airSpeed;
public float airAcceleration;
public float friction;
public float wallClingTime; //time you will 'stick' to the wall after pressing the opposite direction
private float xScale;
public float realSpeed;
private int rightInt = 0;
private int leftInt = 0;
......@@ -28,7 +31,8 @@ public class Walk : AbstractBehavior {
rightInt = 0;
leftInt = 0;
//rightTime = inputButtons[0].
rightTime = inputState.GetButtonHoldTime(right);
leftTime = inputState.GetButtonHoldTime(left);
if (inputState.GetButtonValue(right))
rightInt = 1;
......@@ -40,15 +44,40 @@ public class Walk : AbstractBehavior {
else
leftInt = 0;
if (collisionState.onGround)
if (collisionState.onGround) //movement on ground
{
body.velocity = new Vector2(speed * (rightInt + leftInt), body.velocity.y);
realSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
{
realSpeed = Mathf.Clamp(realSpeed + speed * (rightInt + leftInt), -speed, speed);
}
else
{
if (realSpeed != 0)
{
realSpeed += (-1) * Mathf.Sign(realSpeed) * friction;
if (Mathf.Abs(realSpeed) < friction)
realSpeed = 0;
}
}
body.velocity = new Vector2(realSpeed, body.velocity.y);
} else if (!collisionState.onWall)
{
airSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
{
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
if(Mathf.Abs(airSpeed) <= speed)
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
else
{
if (airSpeed != 0)
{
airSpeed += (-1) * Mathf.Sign(airSpeed) * airAcceleration;
if (Mathf.Abs(airSpeed) < airAcceleration)
airSpeed = 0;
}
}
}
else
{
......@@ -59,9 +88,31 @@ public class Walk : AbstractBehavior {
}
}
body.velocity = new Vector2(airSpeed, body.velocity.y);
} else
} else //handles on the 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);
}
if (leftTime >= wallClingTime)
{
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (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);
}
//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