Where would I start programming hitstop?

I usually ask for debugging advice, but I don’t even know where to start with this.

hitstop is a feature where the game briefly freezes, usually during an attack to add crunch to an action.

I have no idea where to start, I would need to either alter the framerate temporarily or manage to pause logic temporarily

any ideas?

The set_time_step message might be the first thing to consider. Set factor to 0 and this will effectiely freeze everything that uses engine timing - animate functions, timers, delta time etc.

5 Likes

Ok update, I got it to slowdown, now the issue is that I have to return it to normal speed again

function HitStop(delay)
	msg.post("default:/loader#room" .. stage, "set_time_step", {factor = 1/60, mode = 1})
	timer.delay(delay, false, function()
		msg.post("default:/loader#room" .. stage, "set_time_step", {factor = 1, mode = 1})
	end)
end

I’m trying to use this setup so It will speed up again, but from my testing, the timer.delay never fires. any ideas of how to improve this?

What do you get in the console if you add these print statements to your code?

function HitStop(delay)
	print("hit stop start")
	msg.post("default:/loader#room" .. stage, "set_time_step", {factor = 1/60, mode = 1})
	timer.delay(delay, false, function()
		print("hit stop timer finish")
		msg.post("default:/loader#room" .. stage, "set_time_step", {factor = 1, mode = 1})
	end)
end

The time step affects (stops) timer functions so it wont fire. You’ll have to restart it manually somehow, perhaps by checking os.clock() or socket.get_time() .

Would it work to start the timer in another collection and post the message to this proxy when the timer is finished?

I believe so. You could try putting the restart timer in your main collection.

Also you have to control time of the given collection from another one that is not affected by changed time.

E.g. I have a main collection with main script that loads (via collection proxy) a game collection.

[main collection] -> [game collection]

Whenever I want to make slow motion or pause of the game collection, I send a message to main script in main collection to do it. Main script then changes the time step of the game collection.

Main collection goes then in real time and you can set a timer here for whatever time you want. After it ticks, you can set time step of the game collection back to 1.

I send message with a time of delay and to which time step I want to set the game collection, e. G. I want to have a 1 second pause, I sent

{desired_time_step = 0, delay = 1}

If I want a slow motion effect for 2 seconds I sent:

{desired_time_step = 0.5, delay = 2}

Otherwise, if you will set a time step of collection from which you want to start a timer to 0 - this timer will never count down, because you have no time step here!

4 Likes