The RopeJoint restricts the maximum distance between two points. More...

Import Statement: import




Detailed Description

The RopeJoint can be useful to prevent chains of bodies from stretching, even under high load. All 3 properties: bodyA, bodyB and maxLength need to be set to work properly.

Note: If you attempt to change the maximum length during the simulation you will get some non-physical behavior. See DistanceJoint if you want to dynamically change the maxLength.

The DistanceJoint connects two physics bodies with a joint that keeps the distance between these bodies constant. The anchor points are defined relative to the bodies' centers. If no length is specified, it is auto calculated by the distance between the two anchor points.

For a comprehensive documentation of all joints see the Box2D documentation at

Example Usage

The following example shows how two physics bodies are connected with a RopeJoint. The 3 bodies are connected with 2 RopeJoints, which limits the maximum distance between 2 bodies. By clicking on the window, an impulse to the right can be applied to move the 2 lower bodies. The source code of the full example is provided in the rope folder of the Box2D Examples.

 import QtQuick 2.0
 import VPlay 2.0

 GameWindow {
   id: screen

   Scene {
     id: scene

     PhysicsWorld {
       id: world
       debugDrawVisible: true
       gravity.y: 10

     Ball {
       id: ball1
       x: 200
       y: 30
       radius: 15
       // make this ball static, otherwise all would fall down
       // the second ball is connected to the first, and the third to the second
       bodyType: Body.Static

     Square {
       id: square2
       x: 250
       y: 30
       width: 20
       height: 20

     Ball {
       id: ball3
       x: 330
       y: 30
       radius: 10

     RopeJoint {
       id: ropeJoint1
       // the initial distance between ball1 & ball2 is 50, so the rope is longer than the initial distance
       maxLength: 70
       bodyA: ball1.body
       bodyB: square2.body

       //anchors should be in the middle of the items
       localAnchorA: Qt.point(ball1.width/2, ball1.height/2)
       localAnchorB: Qt.point(square2.width/2, square2.height/2)

     RopeJoint {
       id: ropeJoint2
       // the initial distance between ball2 & ball3 is 80, so the rope is longer than the initial distance
       maxLength: 100
       bodyA: square2.body
       bodyB: ball3.body

       //anchors should be in the middle of the items
       localAnchorA: Qt.point(square2.width/2, square2.height/2)
       localAnchorB: Qt.point(ball3.width/2, ball3.height/2)

     Text {
       z: 1 // put on top of DebugDraw in QML renderer
       color: "blue"
       text: "Click to apply an impulse to the right on the green square in the middle"

   } // end of Scene

   MouseArea {
     anchors.fill: parent
     onClicked: {
       square2.body.applyLinearImpulse(Qt.point(100, 0), square2.body.getWorldCenter())

   EntityManager {
     id: entityManager


Property Documentation

localAnchorA : point

The local anchor point relative to the Joint::bodyA center in pixels.

The default is (0, 0), which means the center of Joint::bodyA.

localAnchorB : point

The local anchor point relative to the Joint::bodyB center in pixels.

The default is (0, 0), which means the center of Joint::bodyB.

maxLength : real

The maximum length of the rope. By default it is 0.

Note: It must be larger than 0.005 or the joint will have no effect.

Method Documentation

point getReactionForce(real inv_dt)

Returns the reaction force, in kg*pixels/second^2 for a timestep of length inv_dt, in seconds.

For the Parameter inv_dt, World::timeStep can be used.

real getReactionTorque(real inv_dt)

This is always 0, since a MouseJoint applies only force and no torque.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
create apps
create games
cross platform
native performance
3rd party services
game network
level editor
easiest to learn
biggest time saving
best support