#How to take duration into account of launch script

1 messages · Page 1 of 1 (latest)

uneven kindle
#

What do you mean by "take the duration in account"

proud cloak
#

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

uneven kindle
#

Distance or duration?

proud cloak
#

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

uneven kindle
#

so you want distance / time

proud cloak
#

Exactly!

uneven kindle
#

which is velocity

#

hold on i failed physics lemme check that

proud cloak
#

To get more into the terms

uneven kindle
proud cloak
#

I have displacement, gravity, time

#

And I want initialvelocity

uneven kindle
#

nevermind its the fourteenth studio album by american progressive metal band Dream Theater

#

ok distance/time is speed but whatever

uneven kindle
#

i dont know if this will work, i'm not great at math

proud cloak
#

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

uneven kindle
#

oh yeah my equation doesnt account for gravity

proud cloak
#

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

uneven kindle
#

h1 = starting height
h2 = end height

constant t = time (seconds)

vel(y) = g + (h2 - h1) / t

g = -gravity * t

#

?

proud cloak
#

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

uneven kindle