All Questions


Rabbit One

About Steering.flee_from() function

How flee_from() function should be coded? I know that it's a challenge but I tried to work on this function for a while and I just don't arrive to a solution.

Could you help me by giving me a clue on how to think this? Thanks!

  • Nathan Lovato replied

    I assume you're talking about the challenge, having the leader fade behaviors between fleeing and following the mouse cursor?

    If so, you want to calculate both a flee and an arrive velocity separately using the Steering.flee_from and Steering.arrive_to functions.

    Then, you calculate a weight for the two behaviors based on some maximum distance past which you follow the target position instead of fleeing. A weight of 0 could represent fleeing completely, and a weight of 1 using only the arrive behavior.

    Here's how I calculated the weight in the final assignment's source code:

    var weight: float = clamp(max(to_target - FLEE_THRESHOLD, 0.0) / BEHAVIOR_TRANSITION_RADIUS, 0.0, 1.0)

    I then used the Vector2 class's linear_interpolate method to interpolate between the two:

    _velocity = flee_velocity.linear_interpolate(arrive_velocity, weight)
  • A
    Ewald Anonymous replied

    Hey Nathan,
    I guess, what Rabbit One is referring to is, that in this course (Making a 2D Platformer Character), the Steering.flee_from() function is not shown/discussed at all. You use it in the video, by calling it for calculating the flee_velocity, but you do not show the flee_from-function itself. I think it would be great to at least maybe post it below the video maybe. Not necessary to ceate another video, I think :-)


    Thank you!!


  • Nathan Lovato replied

    Thanks for mentioning it. I'm logging this in my todo. I'll get to it before the wedding! It's in ~2 weeks. Even if we have stuff to prepare, there's still a lot of work to do in parallel.

  • Nathan Lovato replied
    I just updated the lesson with the missing code under the video.