Last active
January 2, 2019 20:46
-
-
Save InfiniteAmmoInc/ec4cd3079c51243a376d8c989941f63f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player : MonoBehaviour | |
{ | |
public float speedX; | |
public float accelX; | |
public float decelX; | |
public float gravity; | |
public float groundVelY; | |
private Vector3 velocity; | |
private BoxMover boxMover; | |
void Awake() | |
{ | |
boxMover = GetComponent<BoxMover>(); | |
} | |
void Update() | |
{ | |
var x = Global.input.GetAxisRaw("Horizontal"); | |
if (Mathf.Abs(x) > 0f) | |
velocity.x = Mathf.MoveTowards(velocity.x, speedX * x, Time.deltaTime * accelX); | |
else | |
velocity.x = Mathf.MoveTowards(velocity.x, 0f, Time.deltaTime * decelX); | |
velocity.y += gravity * .5f * Time.deltaTime; | |
boxMover.MoveX(velocity.x * Time.deltaTime, BoxMover.Slide.Perpendicular); | |
if (!boxMover.MoveY(velocity.y * Time.deltaTime)) | |
velocity.y = groundVelY; | |
else | |
velocity.y += gravity * .5f * Time.deltaTime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment