Commit 26ecec69 by Philipp Adolf

Simplify movement code

parent 9a05dc67
......@@ -117,39 +117,27 @@ public class PlayerControl : MonoBehaviour
}
else
{
bool grounded = isGrounded();
velocity = body2D.velocity;
if (Input.GetKey(keyCodes[(int)Keys.Right]))
{
//normalizedHorizontalSpeed = 1;
//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)
velocity.x = runSpeed;
}
else if (Input.GetKey(keyCodes[(int)Keys.Left]))
{
//normalizedHorizontalSpeed = -1;
//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)
velocity.x = -runSpeed;
}
if (Input.GetKey (keyCodes[(int)Keys.Jump]))
{
//to avoid DOUBLE JUMP
if (isGrounded())
if (grounded)
{
velocity = new Vector2(velocity.x, targetJumpHeight);
velocity.y = targetJumpHeight;
}
}
// apply horizontal speed smoothing it
var smoothedMovementFactor = isGrounded() ? groundDamping : inAirDamping; // how fast do we change direction?
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