I'm not going to lie, I also toyed around with an idea of a pully...
And I might have found a way easier solution than the one I initially thought of!
Here's how it goes:
Instead of treating both platforms seperately, combine them into one single system. What got me thinking is: a pulley is basically a tug-o-war, but with corners.
If you treat your pully as a tug of war, coding it will be a lot less problematic, and like you said, would eliminate that annoying loop-hole of applying forces of the other platform first.
Have one central point, on which both pulleys apply a force, one to the left, and one to the right. This way, the pulleys don't have to ask eachother for their current forces.
Something along the lines of this:
const GRAVITY = 10
const STATIC_FRICTION = 5
var force_platform_one # Pulls central point to the LEFT.
var force_platform_two # Pulls central point to the RIGHT.
var force_centrally # Overall force applied on the central point.
# You'll have to code your own way of applying mass on the platforms
# themselves, but for sake of visualization, these variables represent
# the masses of the platforms themselves, and masses on both platforms.
const MASS_ONE
const MASS_TWO
var mass_on_platform_one
var mass_on_platform_two
func move_platform(platform, force, delta):
# Apply your impulse on a platform here. I have no knowledge of
# this, so I won't add specific code here to prevent confusing you.
# Again, positive force is to the RIGHT, negative to the LEFT.
func move_system(force, delta):
if force < 0 and force < -STATIC_FRICTION:
move_platform(1, force, delta)
move_platform(2, -force, delta)
elif force > 0 and force > STATIC_FRICTION:
move_platform(1, -force, delta)
move_platform(2, force, delta)
else:
print("not move")
func _physics_process(delta):
force_pully_one = GRAVITY * (MASS_ONE + mass_on_platform_one)
force_pully_two = GRAVITY * -(MASS_TWO + mass_on_platform_two)
force_centrally = force_pully_two + force_pully_one
move_system(force_centrally, delta)
This should be the general code needed for it to work.
Also, each body slowly creeps down and the higher the gravity the faster the creep.
This is something in-real-life-physics related, and not engine related.
In real life, there's always some form of FRICTION involved, whether it be tension, movement, air. In this case, it's most likely static friction. Static friction prevents two non-moving objects that touch eachother from moving.
Example: when you try to push a heavy box along the floor, you have to push with a high enough force to get it moving. Concrete has a higher static friction coefficient than ice, which makes it easier to start moving objects that are on ice than it is to start moving objects that are on concrete.
Because you haven't coded in a way of representing said friction, the game does not know how to correctly handle the movement, and as such will make the platforms creep.
The easiest way to implement this is to have a small threshold that has to be crossed in order to actually exert the force. I included it in the code above, in the function move_central_point(force)
.
If you have any more questions, feel free to ask them!
Kind regards,
~FortunePilot