Games [XUI2D] connection force of joints

Discussion in 'Game Development' started by Gunther, Oct 26, 2018.

  1. Gunther

    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Not sure that I understand.

    You can control the motor max torque. Take for example the bridges in the monster truck example. You can set MotorSpeed to 0 and set MaxMotorTorque to a higher value. This will make the bridge less flexible. With a speed of 0 the motors restrain movement.
     
  3. Gunther

    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
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload the project?
     
  5. Gunther

    Gunther Active Member Licensed User

    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
     

    Attached Files:

    Last edited: Oct 29, 2018
  6. ilan

    ilan Expert Licensed User

    Yea u have. What joint are u using?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    1. Use antialiasing. Antialiasing is much faster now and it will make the chain and ball look better.

    Code:
    X2.GraphicCache.PutGraphic2("ball"Array(sb), True3)
    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":
    Code:
    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:
    Code:
    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"100Null)
           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
     
  8. ilan

    ilan Expert Licensed User


    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: Oct 29, 2018
  9. Gunther

    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: Oct 29, 2018
  10. Erel

    Erel Administrator Staff Member Licensed User

    Are you testing it with the force applied over a period?
     
  11. Gunther

    Gunther Active Member Licensed User

    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:

    Code:
    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 = 0Then
                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(00),  X2.CreateVec2(01.))
            
    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(01.))
            
    End If
            
    '
            revdef.DampingRatio = 0.9
            revdef.FrequencyHz = 
    10
            
    '
            world.CreateJoint(revdef)
            
    '
            BodyA.Body = BodyB.Body
        
    Next
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    This is the case with the code I posted in post in post #7. I wasn't able to break the chain with this code.
     
  13. Gunther

    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.
     

    Attached Files:

    Last edited: Oct 29, 2018
  14. ilan

    ilan Expert Licensed User

    Try distance joint
     
  15. Gunther

    Gunther Active Member Licensed User

    With DistanceJoint the same as with wheelJoints.

    Code:
    '
            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.
     
  16. ilan

    ilan Expert Licensed User

    the frequency you set is to high try

    revdef.DampingRatio = 0.5
    revdef.FrequencyHz = 3
     
  17. Gunther

    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.
     
  18. ilan

    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.
     

    Attached Files:

    Last edited: Oct 29, 2018
  19. Gunther

    Gunther Active Member Licensed User

    You mean, may be a wrapper issue of b2box here concerning the joints?
     
  20. ilan

    ilan Expert Licensed User

    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 :)
     
    DonManfred and Peter Simpson like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice