Menu
CoddyTech

Recap: Launch Pad

Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 7 of 63.

challenge icon

Challenge

Easy

The player (a 2 kg Rigidbody) walks along the ground to the orange launch pad, whose Transform is in the pad field. Write Jumper:

  • The left and right arrows walk the player along x at exactly speed m/s (4), using the raw axis; it stands still with no arrow held, and gravity keeps working.
  • Space on the pad launches the player straight up with an impulse of launch (16), so its mass counts. The player is on the pad when its x is less than 1 from the pad's x. Space anywhere else does nothing.
  • No press of Space may be lost: read it in Update(), and do all the physics in FixedUpdate().

Press Play, walk onto the pad and launch, then Check.

Try it yourself

using UnityEngine;

public class Jumper : MonoBehaviour
{
    public float speed = 4f;
    public float launch = 16f;
    public Transform pad;
    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
}

All lessons in Physics and Gameplay