// Called every frame. 'delta' is the elapsed time since the previous frame. public override void _PhysicsProcess(float delta) { if (Input.IsActionPressed("player1_move_up") || Input.IsActionPressed("player2_move_up")) { extendRope(delta); // GD.Print("Rope length now : " + ropeLength); } if (Input.IsActionPressed("player1_move_down") || Input.IsActionPressed("player2_move_down")) { shrinkRope(delta); // GD.Print("Rope length now : " + ropeLength); } doRopePhysics(p1, p2, delta); doRopePhysics(p2, p1, delta); //Only pull them together if they are farther apart then rope is allowed if (ropeLength < p2.Position.DistanceTo(p1.Position)) { Vector2 ropePullVector = (p2.Position - p1.Position).Normalized(); if (!p1.isAnchored && !p2.isAnchored) { //Both moving or in air, make it damped p1.velocity += ropePullVector * ropePullForce * 0.1f; p2.velocity -= ropePullVector * ropePullForce * 0.1f; } else { //One is anchored pull full force p1.velocity += ropePullVector * ropePullForce; p2.velocity -= ropePullVector * ropePullForce; } } p1.move(); p2.move(); }