|
|
@ -16,6 +16,7 @@ public class PlayerController : MonoBehaviour {
|
|
|
|
private Vector3 velocity;
|
|
|
|
private Vector3 velocity;
|
|
|
|
private MoveController moveController;
|
|
|
|
private MoveController moveController;
|
|
|
|
private float velocityXSmoothing;
|
|
|
|
private float velocityXSmoothing;
|
|
|
|
|
|
|
|
private int frameCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void Start() {
|
|
|
|
void Start() {
|
|
|
|
moveController = GetComponent<MoveController>();
|
|
|
|
moveController = GetComponent<MoveController>();
|
|
|
@ -24,22 +25,32 @@ public class PlayerController : MonoBehaviour {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
void Update() {
|
|
|
|
|
|
|
|
frameCount++;
|
|
|
|
|
|
|
|
Debug.LogFormat("Player Update Start {0} ------------------------", frameCount);
|
|
|
|
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
|
|
|
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
|
|
|
|
|
|
|
Debug.LogFormat("Position x: {0} y: {1}", transform.position.x, transform.position.y);
|
|
|
|
|
|
|
|
Debug.LogFormat("Input x: {0} y: {1}", input.x, input.y);
|
|
|
|
float targetX = input.x * moveSpeed;
|
|
|
|
float targetX = input.x * moveSpeed;
|
|
|
|
|
|
|
|
Debug.LogFormat("Target dx: {0}", targetX);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug.LogFormat("Above: {0}", moveController.collisions.above);
|
|
|
|
if (moveController.collisions.above) {
|
|
|
|
if (moveController.collisions.above) {
|
|
|
|
velocity.y = 0;
|
|
|
|
velocity.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug.LogFormat("Left: {0}", moveController.collisions.left);
|
|
|
|
|
|
|
|
Debug.LogFormat("Right: {0}", moveController.collisions.right);
|
|
|
|
if (moveController.collisions.left || moveController.collisions.right) {
|
|
|
|
if (moveController.collisions.left || moveController.collisions.right) {
|
|
|
|
velocity.x = 0;
|
|
|
|
velocity.x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug.LogFormat("Grounded: {0}", moveController.isGrounded);
|
|
|
|
if (moveController.isGrounded) {
|
|
|
|
if (moveController.isGrounded) {
|
|
|
|
if (Input.GetButton("Jump")) {
|
|
|
|
if (Input.GetButtonDown("Jump")) {
|
|
|
|
|
|
|
|
Debug.Log("JUMP");
|
|
|
|
velocity.y = jumpVelocity;
|
|
|
|
velocity.y = jumpVelocity;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
velocity.y = 0;
|
|
|
|
velocity.y = gravity * Time.deltaTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed);
|
|
|
|
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -50,10 +61,9 @@ public class PlayerController : MonoBehaviour {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug.LogFormat("Velocity x: {0} y: {1}", velocity.x, velocity.y);
|
|
|
|
moveController.Move(velocity * Time.deltaTime);
|
|
|
|
moveController.Move(velocity * Time.deltaTime);
|
|
|
|
}
|
|
|
|
Debug.LogFormat("Grounded: {0}", moveController.isGrounded);
|
|
|
|
|
|
|
|
|
|
|
|
void FixedUpdate() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnDestroy() {
|
|
|
|
void OnDestroy() {
|
|
|
|