Skip to content

Easy to use time control for godot. Define multiple clocks to use different time scales on your nodes.

License

Notifications You must be signed in to change notification settings

zekostudio/godot-time-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Godot Time Control Plugin

Godot Time Control

Easy to use time control for godot.
Define multiple clocks to use different time scales on your nodes.

This plugin heavily inspired by CyberSys/ChronosTimeControl Unity asset.

Compatibility

Godot 4.2+

Documentation

  1. Installation
  2. Basic setup
  3. Resources
  4. Nodes
  5. Customization
  6. Examples

Installation

  1. Download the latest release.
  2. Extract the addons/time_control folder to your project's addons folder.
  3. From editor toolbar, go to Project > Project Settings, then in Plugins tab activate TimeControl plugin.

Basic setup

  1. Setup global clocks

    The plugin provides a default ClockController autoload scene located in res://addons/time_control/time_control.tscn which gives you access to the following GlobalClock from anywhere in your project :

    • The WORLD clock, the main clock. The other clocks are parented to this clock
    • The PLAYER clock, manages the player time scale
    • The ENEMY clock, manages the enemies time scale
    • The ENVIRONMENT clock, manages the environment time scale on objects such as ambiant particle effects or animated props

    These Clock nodes are automatically registered to their parent ClockController node, which keeps track of all registered clocks.

    To customize this scene and the registered global clocks, see Customize ClockController autoload scene.


  1. Setup a Timeline

    Add a Timeline node to your scene, and add a ClockConfiguration resource to the global_clock_configuration field.

    Example: If the Timeline is on your player scene, set the player_clock.tres resource (used on the PLAYER GlobalClock) in the global_clock_configuration field.


  1. Use the Timeline node in your script.

    extends CharacterBody2D
    
    const Timeline = preload("res://addons/time_control/timeline.gd")
    const SPEED = 300
    
    @export var timeline: Timeline
    
    func _physics_process(delta: float) -> void:
        var direction = Vector2.ONE
        velocity = direction * SPEED * timeline.time_scale
        move_and_slide() 
  2. Change the time scale from anywhere using ClockController

    extends Node
    
    const ClockConfiguration = preload("res://addons/time_control/clock_configuration.gd")
    
    @export var clock_configuration: ClockConfiguration
    
    func _process(delta: float) -> void:
        ClockController.get_clock(clock_configuration).local_time_scale = 0.5

    or

    extends Node
    
    func _process(delta: float) -> void:
        ClockController.get_clock_by_key("PLAYER").local_time_scale = 0.5

Resources

ClockConfiguration

Resource representing a clock.

Properties

key: String

The clock identifier key.

Nodes

Clock

This Node calculates an indenpendant time scale based on the local_time_scale.

If the clock has a parent, the parent time scale is blended with the local_time_scale.

Properties

local_time_scale: float

The current clock time scale. Set this property to modify the clock time scale.

parent_clock_configuration: ClockConfiguration

Optional

Assign a ClockConfiguration resource as a parent clock if needed.

parent_blend_mode: BlendModeEnum

  • BlendModeEnum.Multiplicative
    Default value
    Multiply the current clock time_scale by the parent clock time_scale

  • BlendModeEnum.Additive
    Adds the current clock time_scale to the parent clock time_scale

Methods

get_time_scale() -> float:

Returns the calculated time scale based on the local_time_scale and the parent clock time scale.

GlobalClock

Inherits Clock

You can retrieve a GlobalClock node from anywhere with the ClockController autoload.

The ClockConfiguration resource parameter is required.

If you need to access the GlobalClock time scale only, we recommend adding a Timeline node to your scene.

Timeline

Add this node anywhere in your scene to access a Clock or a GlobalClock time scale.

Properties

mode: ModeEnum

  • ModeEnum.Global
    Default value
    The Timeline will target a GlobalClock with the global_clock_configuration setting.

  • ModeEnum.Local
    Default value
    The Timeline will target a Clock node with the local_clock setting.

time_scale: float

Returns the target clock calculated time scale.

local_clock: Clock

Assign a Clock node. Works with ModeEnum.Local

global_clock_configuration: ClockConfiguration

Assign a global ClockConfiguration resource. Works with `ModeEnum.Global

ClockController

This node keeps track of all GlobalClock in your project and provides methods to get / add / remove them from anywhere in your project at runtime.

Methods

has_clock(clock_configuration: ClockConfiguration) -> bool

Returns true or false if the GlobalClock matching the clock_configuration is registered.

get_clock(clock_configuration: ClockConfiguration) -> GlobalClock

Returns the registered GlobalClock from the clock_configuration

add_clock(clock_configuration: ClockConfiguration) -> GlobalClock

Registers and returns the new GlobalClock

remove_clock(clock_configuration: ClockConfiguration) -> void

Removes a GlobalClock

Customization

Change the ClockController autoload scene

  1. Copy/paste the res://addons/time_control/time_control.tscn anywhere in your project
  2. Open the copied scene and apply changes (ie: add / remove global clocks)
  3. Go to Project > Project Settings > Addons > Time Control and modify the autoload_path with your new scene path.
    Example: res://scenes/time_control.tscn
  4. Disable/Enable the plugin or reload project to apply changes

Examples

Check out the demo scene res://addons/time_control/demo/demo.tscn

About

Easy to use time control for godot. Define multiple clocks to use different time scales on your nodes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published