Godot - set_fixed_process function

5.4k views Asked by At

I am trying to understand Godot Game engine, I am following a tutorial, and I wrote a breakout game. Here is the padding code:

extends KinematicBody2D

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    var y = get_pos().y
    var x = get_viewport().get_mouse_pos().x
    set_pos(Vector2(x,y))

And I don't understand why I can't use the _fixed_process function without the set_fixed_process function, and what is it's use. What does the function do?

1

There are 1 answers

0
Cody Parker On BEST ANSWER

The _fixed_process() function is a callback that is enabled by calling set_fixed_process(true). This is just like how _process() isn't called unless you enabled the callback with set_process().

Both functions are essentially telling Godot that you want to receive those callbacks in your script when the nodes are processed. And then you're just overriding the _fixed_process() function to capture it in your script.