fix ground sticking thing

master
Jordan Orelli 4 years ago
parent f9383c12f7
commit af44bd5629

@ -498,7 +498,7 @@ PrefabInstance:
- target: {fileID: 4296878337294020286, guid: 19980a8ce8df64b4cbc7cf51fcc077e2,
type: 3}
propertyPath: m_Name
value: Left Status Display
value: Player Status Display
objectReference: {fileID: 0}
- target: {fileID: 6864253409301352422, guid: 19980a8ce8df64b4cbc7cf51fcc077e2,
type: 3}

@ -38,6 +38,7 @@ public class MoveController : MonoBehaviour
if (velocity.y != 0) {
VerticalCollisions(ref velocity);
}
Debug.LogFormat("Moving x: {0} y: {1}", velocity.x, velocity.y);
transform.Translate(velocity);
}
@ -52,9 +53,11 @@ public class MoveController : MonoBehaviour
Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.red);
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, rayLength, collisionMask);
if (hit) {
Debug.LogFormat("Vertical Hit with distance: {0}", hit.distance);
if (directionY > 0) {
collisions.above = true;
} else {
Debug.LogFormat("Hit is below: we are now grounded");
collisions.below = true;
}
velocity.y = (hit.distance - skinWidth) * directionY;
@ -87,7 +90,7 @@ public class MoveController : MonoBehaviour
void UpdateRaycastOrigins() {
Bounds bounds = collider.bounds;
bounds.Expand(skinWidth * -2);
bounds.Expand(skinWidth * -2f);
raycastOrigins.bottomLeft = new Vector2(bounds.min.x, bounds.min.y);
raycastOrigins.bottomRight = new Vector2(bounds.max.x, bounds.min.y);

@ -22,18 +22,18 @@ public class MoveControllerDebugDisplay : MonoBehaviour {
// Update is called once per frame
void Update() {
if (moveController) {
if (moveController.collisions.above) {
aboveDisplay.text = "True";
} else {
aboveDisplay.text = "False";
}
if (moveController.collisions.below) {
belowDisplay.text = "True";
} else {
belowDisplay.text = "False";
}
showBool(aboveDisplay, moveController.collisions.above);
showBool(belowDisplay, moveController.collisions.below);
showBool(leftDisplay, moveController.collisions.left);
showBool(rightDisplay, moveController.collisions.right);
}
}
void showBool(Text label, bool value) {
if (value) {
label.text = "True";
} else {
label.text = "False";
}
}
}

@ -16,6 +16,7 @@ public class PlayerController : MonoBehaviour {
private Vector3 velocity;
private MoveController moveController;
private float velocityXSmoothing;
private int frameCount = 0;
void Start() {
moveController = GetComponent<MoveController>();
@ -24,22 +25,32 @@ public class PlayerController : MonoBehaviour {
}
void Update() {
frameCount++;
Debug.LogFormat("Player Update Start {0} ------------------------", frameCount);
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;
Debug.LogFormat("Target dx: {0}", targetX);
Debug.LogFormat("Above: {0}", moveController.collisions.above);
if (moveController.collisions.above) {
velocity.y = 0;
}
Debug.LogFormat("Left: {0}", moveController.collisions.left);
Debug.LogFormat("Right: {0}", moveController.collisions.right);
if (moveController.collisions.left || moveController.collisions.right) {
velocity.x = 0;
}
Debug.LogFormat("Grounded: {0}", moveController.isGrounded);
if (moveController.isGrounded) {
if (Input.GetButton("Jump")) {
if (Input.GetButtonDown("Jump")) {
Debug.Log("JUMP");
velocity.y = jumpVelocity;
} else {
velocity.y = 0;
velocity.y = gravity * Time.deltaTime;
}
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed);
} 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);
}
void FixedUpdate() {
Debug.LogFormat("Grounded: {0}", moveController.isGrounded);
}
void OnDestroy() {

Loading…
Cancel
Save