In 2DPlatformer example
I want the game object to be jumping when it walks
function Update ()
{
jump.lastButtonTime = Time.time;
ApplyJumping ();
}
function ApplyJumping ()
{
if (jump.lastTime > Time.time)
return;
if (transform.position.y == 1)
{
if (jump.enabled Time.time < jump.lastButtonTime + jump.timeout)
{
transform.Translate(Vector3.up * Time.deltaTime);
movement.verticalSpeed = CalculateJumpVerticalSpeed (jump.height);
movement.inAirVelocity = lastPlatformVelocity;
SendMessage ("DidJump", SendMessageOptions.DontRequireReceiver);
}
}
}
function CalculateJumpVerticalSpeed (targetJumpHeight : float)
{
return Mathf.Sqrt (2 * targetJumpHeight * movement.gravity);
}
function DidJump () {
Character.animation.Play ("jump");
}
The game object can play the “jump” animation when walk, however, it did not jump.
How to fix it?