How To Implement Arriving Behavior With Time Delta?
Solution 1:
EDIT: I missed the main part of your question. There are many ways to get the result you want, but they do so by different means. The easiest I can come up with is probably to skip the steeringForce
for now all together and instead just modify the velocity.
We want a vector such that
desired_velocity = velocity + correction
This is the same as you wrote previously (but for 'steeringForce'):
correction = desired_velocity - velocity
By doing velocity + correction
you will immediately get to the desired velocity, which is usually not what you want as it leads to a very jerky motion. Instead, you could clamp the correction to some value which would lead to a smoother motion:
len = length(correction)
corr_length = len > max_correction ? max_correction : len
correction = correction/len*corr_length
And now you can do
velocity += correction
This should lead to a somewhat dynamic motion, without oscillation.
Explicit time step integration (e.g. an forward Euler in your case) is usually written as
new_acceleration = old_acceleration + (delta_t/mass)*force
^^ note
And similarly,
new_velocity = old_velocity + delta_t*acceleration
new_position = old_position + delta_t*velocity
So to answer your question, you need to multiply by the time step before accumulating:
acceleration.add(force.mult(delta_t/mass));
velocity.add(acceleration.mult(delta_t));
location.add(velocity.mult(delta_t));
Post a Comment for "How To Implement Arriving Behavior With Time Delta?"