I am creating a 2D Sidescrolling game using the basis of the 2D Platformer available from the Unity3D website.
Everything is working fine, I would just like to change a couple of the controls around a bit. Instead of having to hold CTRL (Control) down to run, I would like the user to be able to simply double-tap the right/left arrow keys and have the character run until they are let go.
Would this be possible and, if so, how? Here is what I am looking at:
function UpdateSmoothedMovementDirection () {
var h = Input.GetAxisRaw ("Horizontal");
if (!canControl)
h = 0.0;
movement.isMoving = Mathf.Abs (h) > 0.1;
if (movement.isMoving)
movement.direction = Vector3 (h, 0, 0);
// Grounded controls
if (controller.isGrounded) {
// Smooth the speed based on the current target direction
var curSmooth = movement.speedSmoothing * Time.deltaTime;
// Choose target speed
var targetSpeed = Mathf.Min (Mathf.Abs(h), 1.0);
// Pick speed modifier
if (Input.GetButton("Fire1") canControl) // INSTEAD OF "FIRE1" (CTRL), I WANT 2 HORIZONTAL TAPS
targetSpeed *= movement.runSpeed;
else
targetSpeed *= movement.walkSpeed;
movement.speed = Mathf.Lerp (movement.speed, targetSpeed, curSmooth);
movement.hangTime = 0.0;
}
else {
// In air controls
movement.hangTime += Time.deltaTime;
if (movement.isMoving)
movement.inAirVelocity += Vector3 (Mathf.Sign(h), 0, 0) * Time.deltaTime * movement.inAirControlAcceleration;
}
}