Games [XUI2D] connection force of joints

Gunther

Active Member
Licensed User
Hello,

Do we have any possibility to set the force how strong the joints (B2RevoluteJointDef) are?

If we create a chain it looks more or less like a rubber band.

Greetings
 

Gunther

Active Member
Licensed User
Thanks for this.

The questions is if the strenght of the joint can be changed. Any value to raise the strenght until it gets rupped. Let me try to do a small video for demo.

Unzip the video attached
 

Attachments

Gunther

Active Member
Licensed User
Can you upload the project?
Yes, here it is.

You may move the bal sideways with the arrow keys or remove it by comment out the future Task.

If you force too much the chain with the ball it will break soon.

What about using 'B2ChainShape'?

Chain.PNG
 

Attachments

Last edited:

ilan

Expert
Licensed User
Hello,

Do we have any possibility to set the force how strong the joints (B2RevoluteJointDef) are?

If we create a chain it looks more or less like a rubber band.

Greetings
Yea u have. What joint are u using?
 

Erel

Administrator
Staff member
Licensed User
1. Use antialiasing. Antialiasing is much faster now and it will make the chain and ball look better.

B4X:
X2.GraphicCache.PutGraphic2("ball", Array(sb), True, 3)
2. The ground and ball can be created with Tiled. It would have been simpler.

3. Are you testing it in release mode? It looks quite good here. In debug mode the FPS is set to 30 so the physics are less accurate.

4. Chain shape will not help here. With a chain shape you create a single rigid body. The elements will not move relative to each other.

5. Move the anchor to the center of "pendulum pivot":
B4X:
yAnchor = PendulumPivot.Body.WorldCenter.Y
And check the "draw last" option of the pivot.

This way the first chain element will be partially hidden and it will look better.

6. I've removed the gravity scale changes when I tested it. The more you change the physics settings the more likely you are to encounter simulation issues.

7. ApplyLinearImpulse is equivalent to a very short and strong force. Try it with this code instead:
B4X:
Sub Class_Globals
   Public bw As X2BodyWrapper
   Private x2 As X2Utils 'ignore
   Dim impulsValue As Float = 5
   Private ApplyForce As Boolean
End Sub

Public Sub Initialize (wrapper As X2BodyWrapper)
   bw = wrapper
   x2 = bw.X2
End Sub

Public Sub Tick (GS As X2GameStep)
   If x2.mGame.Jump = True And ApplyForce = False Then
       x2.mGame.Jump = False
       ApplyForce = True
       x2.AddFutureTask(Me, "Stop_Force", 100, Null)
       x2.SoundPool.PlaySound("wing")
   End If
   If ApplyForce Then
       bw.Body.ApplyForce(x2.CreateVec2(0, impulsValue), bw.Body.Position)
   End If

   If GS.ShouldDraw Then
       bw.UpdateGraphic(GS, True)
   End If
End Sub

Sub Stop_Force (ft As X2FutureTask)
   ApplyForce = False
End Sub
 

ilan

Expert
Licensed User
Hello,

Do we have any possibility to set the force how strong the joints (B2RevoluteJointDef) are?

If we create a chain it looks more or less like a rubber band.

Greetings

Yea u have. What joint are u using?
sorry i see now that u r using a revolute joint. why dont u use a distance joint? it makes more sense to use a distance joint and connect the chain parts together. then u can play with the "frequency" and "dumping ratio" parameter to control the strength how 2 parts are connected with each other.

frequency = 0 and dumping ratio = 1 will give u NO elasticy between the parts and they will have strong force that push them from each other like -/- in a magnet.

ps:
dumping ratio should be between 0 - 1
frequency should be between 1 - 5
 
Last edited:

Gunther

Active Member
Licensed User
Dear Erel, Dear Ilan,

thanks for the hints.

On the laptop I always run in Release Mode since there is no big difference in reloading.

Actually I'am (re-)using the Jump Test App for the understanding of the Chain-Object (since the laptop is not reacting of movements like the phone ;o)). So I have something which hits the chain as to see the physics working. Nevertheless thanks to see how differently something may be incorporated.

I also added the Antialiasing to the chain links, too, which for sure gives an improvement on the look of the chain (only).

The rubber band issue is still to check with Ilans approach which I will do, too.

Because by adjusting the forces a little higher (5 Newton) the chain breaks soon.

broken chain.PNG
 
Last edited:

Gunther

Active Member
Licensed User
Are you testing it with the force applied over a period?
Nope, just changed to your version.

But anyhow, the chain is bumping when created. Leaving the ball issue aside.
the WheelJoints are also not working well:

B4X:
    Dim template As X2TileObjectTemplate = TileMap.GetObjectTemplateByName(ObjectLayer, "chain")
    Dim revdef As B2WheelJointDef
'    Dim revdef As B2RevoluteJointDef
   
    For i = 0 To intChainParts
        '
        y = yAnchor - (i * PartHeight) * 0.8
        '
        template.BodyDef.Position = X2.CreateVec2(x, y)
        Dim BodyB As X2BodyWrapper = TileMap.CreateObject(template)
           
        If (i Mod 2 = 0) Then
            BodyB.CurrentFrame = 0
        Else
            BodyB.CurrentFrame = 1
        End If
        '
        If i=0 Then
'            revdef.Initialize(PendulumPivot.Body, BodyB.Body, X2.CreateVec2(x, y))
            revdef.Initialize(PendulumPivot.Body, BodyB.Body, X2.CreateVec2(0, 0),  X2.CreateVec2(0, 1.))
        Else
'            revdef.Initialize(BodyA.Body, BodyB.Body, X2.CreateVec2(x, y))
            revdef.Initialize(BodyA.Body, BodyB.Body,  X2.CreateVec2(0, PartHeight*0.9), X2.CreateVec2(0, 1.))
        End If
        '
        revdef.DampingRatio = 0.9
        revdef.FrequencyHz = 10
        '
        world.CreateJoint(revdef)
        '
        BodyA.Body = BodyB.Body
    Next
 

Gunther

Active Member
Licensed User
Correct, but the chain is bumping like an elastic band also in that code. I assume by its own weight.

Here the Project with WheelJoints which are not doing the job better in this implementation.
 

Attachments

Last edited:

ilan

Expert
Licensed User
Correct, but the chain is bumping like an elastic band also in that code. I assume by its own weight.

Here the Project with WheelJoints which are not doing the job better in this implementation.
Try distance joint
 

Gunther

Active Member
Licensed User
With DistanceJoint the same as with wheelJoints.

B4X:
'
        revdef.Initialize(BodyA.Body, BodyB.Body,  BodyA.Body.Position, BodyB.Body.Position)
        '
        revdef.DampingRatio = 1
        revdef.FrequencyHz = 30
        '
Any higher FrequencyHz will inject a Resonance to the links.
 

ilan

Expert
Licensed User
With DistanceJoint the same as with wheelJoints.

B4X:
'
        revdef.Initialize(BodyA.Body, BodyB.Body,  BodyA.Body.Position, BodyB.Body.Position)
        '
        revdef.DampingRatio = 1
        revdef.FrequencyHz = 30
        '
Any higher FrequencyHz will inject a Resonance to the links.
the frequency you set is to high try

revdef.DampingRatio = 0.5
revdef.FrequencyHz = 3
 

Gunther

Active Member
Licensed User
Please test with the one of post #13 if you go much lower the chain will streched so that the links are not even touching.

Sure one can change also the density to a 4x higher value for the chain links (currently = 1). Than the links are more stiff but this has an impact to the physics as well.
 

ilan

Expert
Licensed User
hmmm after making some tests i created a similar example using @Informatix box2d wrapper for b4j and i am getting a much realistic filling.

rope.gif


note that it runs much smoother on pc then on this gif. i am including the project.
 

Attachments

Last edited:

Gunther

Active Member
Licensed User
You mean, may be a wrapper issue of b2box here concerning the joints?
 

ilan

Expert
Licensed User
You mean, may be a wrapper issue of b2box here concerning the joints?
If u set exactly the same settings like i did to xui2d and u r getting a different result then the answer is yes.

I have included the project try to do the same with xui2d and see the results.

Good luck :)
 
Top