code

mail@pastecode.io avatar
unknown
java
2 years ago
501 B
9
Indexable
Never
public static void vector(Mass obj1, Mass obj2) { 
    float force = force(obj1, obj2);
    
    float dX = Math.abs(obj1.center.x - obj2.center.x);
    float dY = Math.abs(obj1.center.y - obj2.center.y);
    
    float udX = dX / distance(obj1, obj2);
    float udY = dY / distance(obj1, obj2);
    
    float fx = - udX * force;
    float fy = - udY * force;
    
    if(obj1.locked) {
    	obj1.dx = obj1.dx + fx / obj1.mass * deltaTime;
    	obj1.dy = obj1.dy + fy / obj1.mass * deltaTime;
    }
}