Page 1 of 2

[SOLVED] Slow Motion

Posted: Tue Aug 17, 2021 9:14 am
by TRI99ER
I want to make a mechanic, where time slows for a few real seconds.
Actually modifying time flow is easy after the fact, I just need to multiply any changes to velocity by a value I choose (0;1).

The hard part for met to figure out is this: I need to modify every velocity of all entities at the beginning of slow motion by the same value. That is because if I don't do that, every object will retain their initial velocity and it would just mean loss of control over them (because their velocities would be much greater and power to change them would be much weaker).

So I can multiply the velocities by the amount of slow motion, but than as slow motion wear off, I would need to somehow get all the entities back to the velocity, they would have had, if no slowmotion occured. I don't know how exactly to do that the right way and not cause any weird inconsistencies, like sometimes entities just get to insane speeds or slow too much, because their speeds are multiplied at the wrong time.

Re: Slow Motion

Posted: Tue Aug 17, 2021 9:49 am
by TRI99ER
Ok, I figured it out. I just needed to modify x and y values in setLinearVelocity(x, y) instead of modifying the velocity itself. This way velocity remained true the whole time and only it's application was slowed down, which is what I wanted. Still would leave this here for anyone wandering about the same stuff.

So from setLinearVelocity(x, y) to setLinearVelocity(x * slowDownFactor, y * slowDownFactor). And no modification to x and y needed.

Re: [SOLVED] Slow Motion

Posted: Tue Aug 17, 2021 10:01 am
by darkfrei
TRI99ER wrote: Tue Aug 17, 2021 9:14 am I want to make a mechanic, where time slows for a few real seconds.

Code: Select all

function love.update (dt)
	-- do code with normal dt
	if slowmotion_countdown and slowmotion_countdown > 0 then
		slowmotion_countdown = slowmotion_countdown - dt
		dt = dt / 2 -- twice slower
	end
	-- do code with normal or twice smaller dt
end

Code: Select all

function love.keypressed(key, scancode, isrepeat)
	if key == "r" then
		slowmotion_countdown = 2 -- two real seconds
	end
end

Re: [SOLVED] Slow Motion

Posted: Thu Aug 19, 2021 7:52 pm
by TRI99ER
Modifying dt directly is bad practice. Also I already figured out the solution.

Re: [SOLVED] Slow Motion

Posted: Thu Aug 19, 2021 8:02 pm
by pgimeno
TRI99ER wrote: Thu Aug 19, 2021 7:52 pm Modifying dt directly is bad practice. Also I already figured out the solution.
You want to modify time, and doing exactly that is bad practice?
Image

Re: [SOLVED] Slow Motion

Posted: Thu Aug 19, 2021 8:13 pm
by GVovkiv
pgimeno wrote: Thu Aug 19, 2021 8:02 pm You want to modify time, and doing exactly that is bad practice?
Image
It can break the interdimensional time continuum, therefore, I advise you to avoid time modification if you don't want that happens

Re: [SOLVED] Slow Motion

Posted: Thu Aug 19, 2021 9:13 pm
by darkfrei
GVovkiv wrote: Thu Aug 19, 2021 8:13 pm It can break the interdimensional time continuum, therefore, I advise you to avoid time modification
You can make the dt2 = dt/2 and use this value for things, that must be twice slower.

Re: [SOLVED] Slow Motion

Posted: Thu Aug 19, 2021 10:21 pm
by GVovkiv
darkfrei wrote: Thu Aug 19, 2021 9:13 pm
GVovkiv wrote: Thu Aug 19, 2021 8:13 pm It can break the interdimensional time continuum, therefore, I advise you to avoid time modification
You can make the dt2 = dt/2 and use this value for things, that must be twice slower.
So, you want to break our timeline with that dark magic, yeah?

Re: [SOLVED] Slow Motion

Posted: Thu Aug 19, 2021 10:39 pm
by darkfrei
GVovkiv wrote: Thu Aug 19, 2021 10:21 pm
darkfrei wrote: Thu Aug 19, 2021 9:13 pm
GVovkiv wrote: Thu Aug 19, 2021 8:13 pm It can break the interdimensional time continuum, therefore, I advise you to avoid time modification
You can make the dt2 = dt/2 and use this value for things, that must be twice slower.
So, you want to break our timeline with that dark magic, yeah?
We have more than one timeline, obviously it depends on the mass near you.
(Nice game idea with relativism)

Re: [SOLVED] Slow Motion

Posted: Thu Aug 19, 2021 10:49 pm
by Gunroar:Cannon()
pgimeno wrote: Thu Aug 19, 2021 8:02 pm You want to modify time, and doing exactly that is bad practice?
Image
:rofl: :rofl: :rofl:
GVovkiv wrote: Thu Aug 19, 2021 10:21 pm So, you want to break our timeline with that dark magic, yeah?
:rofl: You can preserve the time line continuum by going back to the origional time line after the modification. Using dark magic twice. Two negatives = 1 positive :P

Code: Select all

olddt = dt

dt = dt/slow

updateEntities(dt)

dt = olddt

updateThe Rest