Commit f7c174b8 authored by Luke A Smith's avatar Luke A Smith

Merge branch 'walk' into 'master'

Added walk script

See merge request !6
parents aafa3923 ce767374
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Walk : AbstractBehavior {
public int speed;
private float airSpeed;
public float airAcceleration;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
Buttons left = inputButtons[0];
Buttons right = inputButtons[1];
int rightInt = 0;
int leftInt = 0;
if (inputState.GetButtonValue(right))
rightInt = 1;
else
rightInt = 0;
if (inputState.GetButtonValue(left))
leftInt = -1;
else
leftInt = 0;
if (collisionState.onGround)
{
body.velocity = new Vector2(speed * (rightInt + leftInt), body.velocity.y);
} else
{
airSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
{
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;
}
}
body.velocity = new Vector2(airSpeed, body.velocity.y);
}
}
}
fileFormatVersion: 2
guid: fffc5061cced9b8498b9146e0712c85e
timeCreated: 1486687201
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 79af5acd6c178454090143472b307c76
timeCreated: 1486692331
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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