Using dt in render script (SOLVED)

Is there any way to use dt in the update function of render script? I want to make backround animation using self.clear_color
Thanks.

1 Like

It’s not passed to the update() of the render script. But you can send dt from another script to the render script.

function update(self, dt)
    msg.post("@render:", "set_dt", { dt = dt })
end
3 Likes

@sicher thank you but it’s not very fast solution, I believe. I have just set dt as a constant (self.dt = 1 / 60).

An alternative solution would be to calculate dt yourself in the render script, but it would be a general dt and only correspond to the “variable dt” setting in game.project. Something like this;

function init(self)
    self.last_frame = socket.gettime()
end

function update(self)
    local current_frame = socket.gettime()
    local dt = current_frame - self.last_frame
    self.last_frame = current_frame

    -- ...
end

An alternative, since you want to animate the clear color, you could do this inside a regular GO script, maybe something like this:

function init(self)
    self.anim = 0.0
end

function update(self, dt)
    self.anim = (self.anim + dt) % 1.0
    msg.post("@render:", "clear_color", { color = vmath.vector4(self.anim, 0, 0, 1) } )
end
3 Likes