# Objects Evade or Repell eachother in Animation Nodes

I'm trying to achieve this. Sphere's displacing the position of other objects as they move through them. Sorta like someone pushing through a crowd.

I've managed to get this far in AN but adding more than one effector is where I'm getting stuck.

It was easy enough to displace the arrows based on an effector but I couldn't get them to choose the most efficient direction to travel. That is why I made them point towards the effector so they could be pushed back on their local X-axis. This adds complexity to the setup that I can't solve now that I need the arrows to "point" to more than one Effector.

I divide this Repeller Effect into parts:

1. Offsetting the locations with multiple-object effectors.
2. Changing the direction of arrows with respect to the effectors' location.

Part-1: Idea is, we offset the locations (grid-points) using the first effector then use those offsetted grid-points for next the effector with the help of reinitializing option of the loop node.

We want to offset location using more than one effectors (I'm using empties objects), so we need the Loop-Node and looping over effectors to get the location of each effector.

Then I have added the Vector-list (name it as grid-points) as "new parameter" in the Loop-Node and calculated the offset by taking the difference between the effector's location and grid-points using Vector-Node which I use as offset-list for the Offset-Node to repel the grid-points based on the Object-Falloff,

Now, select the Loop-Node then open the N-panel and reinitialize the grid-points and also enable the output option so that we can use these grid-points for instanced objects which are arrows in this case but you can use any object. Here is the complete setup for this part:

Part-2: To calculate the direction for the arrows, I take the difference of effector's location and offsetted grid-points. Now, to get the effect that arrows point toward the effector based on the distance from the effector (e.g. like in case of electric field), so we have to normalize directions w.r.t inverse of distances using Math-Node. You can also change the direction of arrows (i.e. point away or toward the effector) by changing the 1 to -1 in the Math-Node.

Next, we add these normalized directions for all effectors which we can do that by creating an empty Vector-list from "new parameter" then reinitializing it and enable the output option for further use in the N-panel,

From the outputs of Loop-Node, first, normalize the directions to one then connect them to Direction-To-Rotation node, and then to the Object-Transforms-Output Node,

The complete Node-Tree (I have added the Switch-Node to change arrow direction):

Note:- This Node-Tree also works for 3DGrid-Points.

• Wow, @3DsinghVFX you are amazing. There is a lot here I didn't know. Thank you.
– Alan
Aug 25 '19 at 10:16