-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheTractors.jsx
23 lines (20 loc) · 1012 Bytes
/
eTractors.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
'createEffector': function(effectorLayer, particlePosition) {
const getLongestSide = (layer) => {
const layerRect = layer.sourceRectAtTime(0, false);
return Math.max(layerRect.width, layerRect.height);
}
const vectorToEffector = effectorLayer.sub(effectorLayer.transform.position, particlePosition);
const vectorFromEffector = effectorLayer.sub(particlePosition, effectorLayer.transform.position);
const distanceFromEffector = effectorLayer.length(vectorToEffector);
const effectorRadius = getLongestSide(effectorLayer);
const moveAmount = effectorLayer.ease(distanceFromEffector, effectorRadius, 0, 1, 0);
const moveToEffector = effectorLayer.mul(vectorToEffector, moveAmount);
const moveAwayFromEffector = effectorLayer.mul(vectorFromEffector, moveAmount);
return {
attract: moveToEffector,
avoid: moveAwayFromEffector,
strength: moveAmount,
};
}
}