You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm attempting to achieve and effect where the attraction between bodies varies depending on their distance and mass (like a magnet). I've attempted to use the following function, using the standard vector math formula, but so far have not been able to replicate the effect:
function(bodyA, bodyB) {
let vx = bodyB.position.x - bodyA.position.x;
let vy = bodyB.position.y - bodyA.position.y;
let m = Math.sqrt(vx * vx + vy * vy);
let dx = vx / m;
let dy = vy / m;
return {
x: (dx * (bodyA.mass * bodyB.mass)) / m,
y: (dy * (bodyA.mass * bodyB.mass)) / m
};
}
Probably I don't understand properly which x/y values should be returned. Any assistance would be greatly appreciated! 😄
The text was updated successfully, but these errors were encountered:
Hello!
I'm attempting to achieve and effect where the attraction between bodies varies depending on their distance and mass (like a magnet). I've attempted to use the following function, using the standard vector math formula, but so far have not been able to replicate the effect:
Probably I don't understand properly which x/y values should be returned. Any assistance would be greatly appreciated! 😄
The text was updated successfully, but these errors were encountered: