Recap: Launch Pad
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 7 of 71.
This recap puts the chapter together: a velocity set in FixedUpdate(), an impulse that counts the mass, and a key read in Update() so no press is lost.
Challenge
EasyWalk the player to the launch pad and launch it.
- In
Update(), set abool launchPressedonInput.GetKeyDown(KeyCode.Space). - In
FixedUpdate(), setrb.linearVelocityfrom the raw Horizontal axis timesspeed, keeping its y. - When
launchPressedis set, addVector3.up * launchwithForceMode.Impulseonly if x is less than 1 frompad.position.x, then clear it.
Press Play, walk onto the pad and press Space. 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>();
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Physics and Gameplay
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad4Coroutines
InvokeInvokeRepeating, CancelInvokeYour First CoroutineLoops in CoroutinesStopping CoroutinesRecap: Countdown10Project: Arena Escape
The ArenaHunters2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable WallPractice on your own: Unity playground