After Effects Expression - Force Field

This Expression will move the planets around the Spaceship based on the field's strength.

Apply this Expression on each planet's position:

//Getting the strength value of the force field
var reflectRadius = thisComp.layer("SPACESHIP").effect("DEFLECT RADIUS")("Slider");

//Calculating the total distance between the layers and the distance on each axis
var lengthX = value[0] - thisComp.layer("SPACESHIP").transform.position[0];
var lengthY = value[1] - thisComp.layer("SPACESHIP").transform.position[1];
var distance = length(value, thisComp.layer("SPACESHIP").transform.position);

//Calculating the angle between the layers,
//this will allow us to get how much force will be applied into each axis

var angle = Math.atan2(lengthY, lengthX);
var cosine = Math.cos(angle);
var sine = Math.sin(angle);
var moveRadius = ease(distance, reflectRadius, 0, reflectRadius, 0);

//Applying the final value
[value[0]+moveRadius*cosine, value[1]+moveRadius*sine];

Last updated