#How to make an object reach somewhere within a timeframe?

1 messages · Page 1 of 1 (latest)

eager oriole
#

I'm moving one object to another and I need it to reach the other after exactly 30 seconds, but I'm stuck... If I add the position at 30hz, then running below 30 frames, or any stutters, is going to mess up the time frame. How can I keep it consistent?

arctic oar
#

Also questions like these tha are mainly math based any AI can answer

eager oriole
#

I just need to divide the distance by the time but I don't know how

arctic oar
eager oriole
arctic oar
arctic oar
dusky slate
# eager oriole I just need to divide the distance by the time but I don't know how

start = starting position
end = destination
step size = distance from start to end / time
elapsed time = time - float variable saved to time

start + (direction to end normalized * elapsed time * step size)

using float variable makes completely dependant on time regardless of update rate. After time is up, you may still need to set the object at the start bc floating point but ye

arctic oar
#

FYI ai gave me the same exact thing @eager oriole

#

gave me that method and a lerp method

dusky slate
#

but in code it makes it clearer that start & float variable need to be set before anything

dusky slate
#

then if i had to complete it, i would use state machine (with execution int switch, not the built in)
IGLT = Instance Get Lifetime

30Hz, if object authority
Switch(State, [1,2]):

  • Failed:
    • Do Nothing
  • 1:
    • Start pos = get position(object)
    • Start time = IGLT
    • End time = IGLT + duration
    • Set Rotation(object, destination - Start pos)
    • State = 2
  • 2:
    • If IGLT > End time:
      • Then:
        • Set Position(object, destination)
        • State = 0
      • Else:
        • Set Position(object, Lerp(Start pos, destination, (IGLT - Start time) / duration))
#

@eager oriole

eager oriole