4
$\begingroup$

Good evening. i'm working on a high school project from my class, and trying to make an animation in blender that will be a major part of the presentation. for the first scene I've modeled a high bridge that runs on an array, and a few low poly cars to simulate the traffic, but i want them to be placed randomly while staying in there lanes. I plan to animate the cars on a starting, and stopping on another layer, but I've gotten stuck finding a way to animate the cars on the road. while allowing them to keep there random colors, and while also having a random placement. i can give them random colors by simply copying, and paste, but an array will make them develop a pattern. Thank you for taking the time to read, and i hope you can help me. enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ First though, have a look to animation nodes github.com/JacquesLucke/animation_nodes/releases $\endgroup$
    – lemon
    Commented Apr 1, 2017 at 20:36
  • $\begingroup$ Thank you for telling me about that, but I've decided to go with a different simpler method of animating this. $\endgroup$ Commented Apr 2, 2017 at 19:32

1 Answer 1

4
$\begingroup$

Primitive Method

A primitive way to do this is to sample a noise function and use the noise value as an offset to the original location.

result

offset = noise(scale_pos * car_starting_position, scale_time * frame)
final_position = frame * car_speed + car_starting_position + scale_noise * offset

scale_pos would be a scaling factor which influences the correlation of subsequent cars. A larger value would mean that subsequent cars would be sampled further apart which would result in more “tailgating”. Smaller values would make the flow more uniform.

scale_time controls how fast the offset changes with time. The larger the value, the more often drivers will drive back and forth in their spot.

And scale_noise will be a final factor to control the size of the offset. It has to be small enough, w.r.t. the mean gap size to guarantee that the cars don't intersect, and w.r.t. the car_speed so that there aren't any cars which drive backwards.

Implementation

I implemented this method with the add-on Animation Nodes in the tree shown below. The shown values are the ones used in the animation above. Width and height as well as mean gap size is one unit.

node tree

The default car position is stored as an Object ID Key which is set by selecting all objects and pressing Create in the 3DView's Tool Shelf in the AN tab.

ID Key

To use the noise function in AN's expression node you have to add the mathutils module in the Advanced Node Settings in the node's properties.

expression node

Precise Method

An alternative would be to calculate the car positions directly with some implementation of the Nagel-Schreckenberg model, which would also have the advantage of being more suitable for slow speeds or cars which are actually stopping.

However, all implementations of these models that I've encountered use an abstraction that might not be good enough for a scene like this as the gap size in real traffic is usually rather large compared to the car length. If you use some trucks in a scene with slow traffic then I assume you would have to include the vehicle length in the model.

If you choose to use Animation Nodes for this approach then there is a useful setting for the Script node, or more precise, the Invoke Subprogram of a script, that lets you cache the output of a script. E.g. you can use one script to calculate all car positions at once (or read them from a file) and another script to actually place the cars after each frame.

caching options

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .