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.
[SOLVED] Slow Motion
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] Slow Motion
Last edited by TRI99ER on Tue Aug 17, 2021 9:49 am, edited 1 time in total.
Re: Slow Motion
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.
So from setLinearVelocity(x, y) to setLinearVelocity(x * slowDownFactor, y * slowDownFactor). And no modification to x and y needed.
Re: [SOLVED] Slow Motion
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
Modifying dt directly is bad practice. Also I already figured out the solution.
Re: [SOLVED] Slow Motion
You want to modify time, and doing exactly that is bad practice?
Re: [SOLVED] Slow Motion
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.
Re: [SOLVED] Slow Motion
You can make the dt2 = dt/2 and use this value for things, that must be twice slower.
Re: [SOLVED] Slow Motion
So, you want to break our timeline with that dark magic, yeah?
Re: [SOLVED] Slow Motion
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: [SOLVED] Slow Motion
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
Code: Select all
olddt = dt
dt = dt/slow
updateEntities(dt)
dt = olddt
updateThe Rest
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 8 guests