Commit 26ecec69 by Philipp Adolf

Simplify movement code

parent 9a05dc67
...@@ -117,39 +117,27 @@ public class PlayerControl : MonoBehaviour ...@@ -117,39 +117,27 @@ public class PlayerControl : MonoBehaviour
} }
else else
{ {
bool grounded = isGrounded();
velocity = body2D.velocity; velocity = body2D.velocity;
if (Input.GetKey(keyCodes[(int)Keys.Right])) if (Input.GetKey(keyCodes[(int)Keys.Right]))
{ {
//normalizedHorizontalSpeed = 1; velocity.x = runSpeed;
//if (transform.localScale.x < 0f)
// transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
//go right:
velocity = new Vector2(runSpeed,velocity.y);
//if (_controller.isGrounded)
} }
else if (Input.GetKey(keyCodes[(int)Keys.Left])) else if (Input.GetKey(keyCodes[(int)Keys.Left]))
{ {
//normalizedHorizontalSpeed = -1; velocity.x = -runSpeed;
//if (transform.localScale.x > 0f)
// transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
velocity = new Vector2(-runSpeed, velocity.y);
//if (_controller.isGrounded)
} }
if (Input.GetKey (keyCodes[(int)Keys.Jump])) if (Input.GetKey (keyCodes[(int)Keys.Jump]))
{ {
//to avoid DOUBLE JUMP //to avoid DOUBLE JUMP
if (isGrounded()) if (grounded)
{ {
velocity = new Vector2(velocity.x, targetJumpHeight); velocity.y = targetJumpHeight;
} }
} }
// apply horizontal speed smoothing it // apply horizontal speed smoothing it
var smoothedMovementFactor = isGrounded() ? groundDamping : inAirDamping; // how fast do we change direction? var smoothedMovementFactor = isGrounded() ? groundDamping : inAirDamping; // how fast do we change direction?
velocity.x = Mathf.Lerp(velocity.x,0, Time.deltaTime * smoothedMovementFactor); velocity.x = Mathf.Lerp(velocity.x,0, Time.deltaTime * smoothedMovementFactor);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment