#How to take duration into account of launch script
1 messages · Page 1 of 1 (latest)
Let's say I have a GameObject at (0, -5, 0) and another one at (0, 10, 0)
If I tell them to reach a height of 20 before falling down, they both will, independent of their starting height
But they'll obviously take different times to do so
I want to tell them not only to reach a given height, but to do so within a given duration
Distance or duration?
In this example, I'd want both GameObjects to reach the height of 20 in the same duration
Without using Lerp
Just by setting an initial velocity
so you want distance / time
Exactly!
To get more into the terms
nevermind its the fourteenth studio album by american progressive metal band Dream Theater
ok distance/time is speed but whatever
`h1 = starting height
h2 = end height
constant t = time (seconds)
vel(y) = (h2 - h1) / t
`
i dont know if this will work, i'm not great at math
Start
// pseudo
totalDisplacement = heightToReach - my height;
velocity.y = Mathf.Sqr(totalDisplacement * -2f * -gravity);
Update
velocity.y -= gravity * Time.deltaTime;
transform.position += velocity * Time.deltaTime;
That's my code, basically
And it works as it should
oh yeah my equation doesnt account for gravity
But I don't know how to build the duration into that
My guess was for example calculating gravity within the displacement and then using duration instead of gravity in Sqrt
But I think that's bullshit, my math is terrible
h1 = starting height
h2 = end height
constant t = time (seconds)
vel(y) = g + (h2 - h1) / t
g = -gravity * t
?
Mhmmm I think I'm understanding what you're trying to do
I definitely got an idea that I'll test
But if anyone knows the solution, I'd be glad xd
Thx for your help so far
you can also try #⚛️┃physics