Recap: Bullet Time
Part of the Building Real Games section of Coddy's Unity journey. Lesson 37 of 60.
This chapter froze, slowed and restarted game time. Bullet time puts it together: a smaller Time.timeScale, a physics step to match, and a meter that counts real seconds.
Challenge
MediumGive the game bullet time.
- In
Update(), while Space is held andfocus > 0f: time scaleslowScale, physics step0.02f * slowScale, andfocusdrains 1 a real second, not below 0. - Otherwise scale
1f, step0.02f; with Space up,focusrefillsrechargea real second, up tomaxFocus. - Then
focusBar.fillAmount = focus / maxFocus;
Press Play and hold Space: the rain slows. Then Check.
Try it yourself
using UnityEngine;
using UnityEngine.UI;
public class BulletTime : MonoBehaviour
{
public float slowScale = 0.2f;
public float maxFocus = 2f;
public float recharge = 0.5f;
public Image focusBar;
float focus;
void Start()
{
focus = maxFocus;
}
void Update()
{
// Bullet time while Space is held and focus is left, normal time otherwise, then the bar
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Building Real Games
2Buttons 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