Recap: Launch Pad
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 7 of 63.
Challenge
EasyThe 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
speedm/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 inFixedUpdate().
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
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable Wall