Menu
CoddyTech

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 icon

Challenge

Medium

Give the game bullet time.

  1. In Update(), while Space is held and focus > 0f: time scale slowScale, physics step 0.02f * slowScale, and focus drains 1 a real second, not below 0.
  2. Otherwise scale 1f, step 0.02f; with Space up, focus refills recharge a real second, up to maxFocus.
  3. 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
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Building Real Games

Practice on your own: Unity playground