Moving Platforms
Part of the Building Real Games section of Coddy's Unity journey. Lesson 50 of 60.
Challenge
MediumMake the blue platform glide over the gap. Riding it comes next.
- In
MovingPlatform, add[SerializeField]floatsdistance = 3fandspeed = 1.5f, andpublic Vector3 delta;. - In
Update(), glide from the start todistanceunits along +x atspeed, back again, and repeat. - Set
deltato the position after the move minus the position before.
Press Play: the platform glides out and back. Then Check.
Try it yourself
using UnityEngine;
public class MovingPlatform : MonoBehaviour
{
// A later lesson fills this in: a platform that glides back and forth.
}
All lessons in Building Real Games
10Project: 3D Platformer
The CourseMoving Platforms2Buttons and Screens
Buttons and onClickLambdasWiring in the InspectorPanels On and OffHealth BarsRecap: Upgrade Shop5Saving with PlayerPrefs
Save a NumberLoad with a DefaultHigh ScoreSave SettingsRecap: Coins in the Bank3The Game Manager
One Script Runs the GameThe SingletonGame StatesSwitching on the StateRecap: Round Manager6Project: Endless Runner
Three LanesObstacles Ahead9The New Input System
Two Input SystemsKeyboard and MousePressed This FrameInput ActionsRecap: Input SwapPractice on your own: Unity playground