Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualÁlvaro

Posted 25 November 2012 - 04:29 AM

Thank you for the tip.

I noticed that when I change this line:

Velocity = Velocity + acceleration * deltaTime;

into:
Velocity = Velocity + acceleration;

It appears to work like I expect, it also fixes the seek steering behavior. Can anyone explain this? I thought deltaTime had to be included when calculating both velocity and position. Maybe there is still a problem hidden somewhere.


You should definitely keep the multiplication by deltaTime in place. If removing it gives you the behavior you like, you can also get it by dividing the force by deltaTime.

It looks to me like the setup in the code you are using is strange and complicated. I would consider much simpler code, like this (in C++):

Vector2D force_to_arrive(Point2D position, Vector2D velocity, Point2D target_position) {
  const double c = 4.0;
  const double k = 4.0;

  Vector2D position_difference = target_position - position;
  return k * position_difference - c * velocity;
}

#1Álvaro

Posted 25 November 2012 - 04:03 AM

Thank you for the tip.

I noticed that when I change this line:

Velocity = Velocity + acceleration * deltaTime;

into:
Velocity = Velocity + acceleration;

It appears to work like I expect, it also fixes the seek steering behavior. Can anyone explain this? I thought deltaTime had to be included when calculating both velocity and position. Maybe there is still a problem hidden somewhere.


You should definitely keep the multiplication by deltaTime in place. If removing it gives you the behavior you like, you can also get it by dividing the force by deltaTime.

It looks to me like the setup in the code you are using is strange and complicated. I would consider much simpler code, like this (in C++):

Vector2D force_to_arrive(Point2D position, Vector2D velocity, Point2D target_position) {
  const double c = 0.5;
  const double k = 4.0;

  Vector2D position_difference = target_position - position;
  return k * position_difference - c * velocity;
}

PARTNERS