[SOLVED] Slow Motion

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
TRI99ER
Prole
Posts: 13
Joined: Fri May 28, 2021 3:28 pm

[SOLVED] Slow Motion

Post 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.
Last edited by TRI99ER on Tue Aug 17, 2021 9:49 am, edited 1 time in total.
TRI99ER
Prole
Posts: 13
Joined: Fri May 28, 2021 3:28 pm

Re: Slow Motion

Post 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.
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

Re: [SOLVED] Slow Motion

Post 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
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
TRI99ER
Prole
Posts: 13
Joined: Fri May 28, 2021 3:28 pm

Re: [SOLVED] Slow Motion

Post by TRI99ER »

Modifying dt directly is bad practice. Also I already figured out the solution.
User avatar
pgimeno
Party member
Posts: 3593
Joined: Sun Oct 18, 2015 2:58 pm

Re: [SOLVED] Slow Motion

Post 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
User avatar
GVovkiv
Party member
Posts: 678
Joined: Fri Jan 15, 2021 7:29 am

Re: [SOLVED] Slow Motion

Post 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
Last edited by GVovkiv on Thu Aug 19, 2021 10:24 pm, edited 1 time in total.
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

Re: [SOLVED] Slow Motion

Post 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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
GVovkiv
Party member
Posts: 678
Joined: Fri Jan 15, 2021 7:29 am

Re: [SOLVED] Slow Motion

Post 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?
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

Re: [SOLVED] Slow Motion

Post 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)
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1101
Joined: Thu Dec 10, 2020 1:57 am

Re: [SOLVED] Slow Motion

Post 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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests