# Train Simulation: Seek and Flee Steering Behaviors. Simon’s own code.

Simon’s sketch is available online at https://alpha.editor.p5js.org/simontiger/sketches/B1GtGlDGb

This train simulation is Simon’s own code using the seek and flee steering behaviors…

and a slider:

# Steering Behaviors: flow field, dot product, scalar projection

Simon’s big project the last couple of days was about making a steering behaviors database, complete with a navigation menu (in Cloud9):

He managed to finish the first two examples – “Seek and Flee” and “Pursuit and Evasion” – and worked on the Flow Field Following and Path Following.

As recommended by Daniel Shiffman, Simon largely relied on the paper called Steering Behaviors For Autonomous Characters (written by Craig W. Reynolds from Sony). As Simon told me, he tried to guess the code to make the static drawings in the paper come to life. For instance, for the “Seek and Flee” example, Simon animated this drawing:

Simon also made a “Seek” example in the language called Lua (from the Codea app):

The second example was about Pursuit and Evasion:

Simon also explained to me how Flow Field Following worked:

Another steering behavior he scrutinized was Path Following. For Path Following, he first had to learn what the “dot product” was. In math, the dot product or scalar product is an algebraic operation that takes two equal-length sequences of numbers (usually coordinate vectors) and returns a single number.

The way Simon learns is usually by studying (deconstructing) and memorizing the formulas (even if he doesn’t fully understand them in the beginning). After he comes back to the formula later on he seems to have grasped the meaning of it.  I often observe him actually apply different formulas in real life. When it comes to the “dot product”, Simon is in the beginning of the learning curve:

The formula for scalar projection is:

or the way Simon put it: