|
|
@ -4,7 +4,6 @@ using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(MoveController))]
|
|
|
|
[RequireComponent(typeof(MoveController))]
|
|
|
|
public class PlayerController : MonoBehaviour {
|
|
|
|
public class PlayerController : MonoBehaviour {
|
|
|
|
|
|
|
|
|
|
|
|
public float jumpHeight = 4f;
|
|
|
|
public float jumpHeight = 4f;
|
|
|
|
public float timeToJumpApex = 0.4f;
|
|
|
|
public float timeToJumpApex = 0.4f;
|
|
|
|
public float moveSpeed = 6f;
|
|
|
|
public float moveSpeed = 6f;
|
|
|
@ -25,29 +24,32 @@ public class PlayerController : MonoBehaviour {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
void Update() {
|
|
|
|
if (moveController.collisions.below || moveController.collisions.above) {
|
|
|
|
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
|
|
|
|
|
|
|
float targetX = input.x * moveSpeed;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (moveController.collisions.above) {
|
|
|
|
velocity.y = 0;
|
|
|
|
velocity.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (moveController.collisions.left || moveController.collisions.right) {
|
|
|
|
if (moveController.collisions.left || moveController.collisions.right) {
|
|
|
|
velocity.x = 0;
|
|
|
|
velocity.x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Space) && moveController.collisions.below) {
|
|
|
|
|
|
|
|
velocity.y = jumpVelocity;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float targetX = input.x * moveSpeed;
|
|
|
|
|
|
|
|
if (moveController.isGrounded) {
|
|
|
|
if (moveController.isGrounded) {
|
|
|
|
|
|
|
|
if (Input.GetButton("Jump")) {
|
|
|
|
|
|
|
|
velocity.y = jumpVelocity;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
velocity.y = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed);
|
|
|
|
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
|
|
|
|
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
|
|
|
|
|
|
|
|
velocity.y += gravity * Time.deltaTime;
|
|
|
|
|
|
|
|
if (velocity.y < maxFallSpeed) {
|
|
|
|
|
|
|
|
velocity.y = maxFallSpeed;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
velocity.y += gravity * Time.deltaTime;
|
|
|
|
|
|
|
|
if (velocity.y < maxFallSpeed) {
|
|
|
|
|
|
|
|
velocity.y = maxFallSpeed;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
moveController.Move(velocity * Time.deltaTime);
|
|
|
|
moveController.Move(velocity * Time.deltaTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|