Skip to content

Instantly share code, notes, and snippets.

@InfiniteAmmoInc
Last active January 2, 2019 20:46
Show Gist options
  • Save InfiniteAmmoInc/ec4cd3079c51243a376d8c989941f63f to your computer and use it in GitHub Desktop.
Save InfiniteAmmoInc/ec4cd3079c51243a376d8c989941f63f to your computer and use it in GitHub Desktop.
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