Skip to content

Instantly share code, notes, and snippets.

@jquave
Created August 24, 2014 06:34
Show Gist options
  • Save jquave/19430f165c67611ba933 to your computer and use it in GitHub Desktop.
Save jquave/19430f165c67611ba933 to your computer and use it in GitHub Desktop.
float xVel = rigidbody2D.velocity.x;
xVel += Time.deltaTime*playerState.playerSettings.walkSpeed*input.directionalPad.x*playerState.playerSettings.walkAcceleration;
float sign = xVel/Mathf.Abs(xVel);
if(Mathf.Abs(xVel)>playerState.playerSettings.maxWalkSpeed) xVel = sign*playerState.playerSettings.maxWalkSpeed;
// TODO: Use a non-animation based method here
if(player.playerAnimation.currentAnimation=="CrowSprint") xVel *= 1.4f; // Speed up in sprint animation
rigidbody2D.velocity = new Vector2(xVel, rigidbody2D.velocity.y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment