Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Is there a Rope Joint alternative? — Gideros Forum

Is there a Rope Joint alternative?

DikkesnoekDikkesnoek Member
edited November 2012 in General questions
Hi,

I am still working on an elastic rope which can be stretched by touch events. From
different sources, I've read that you need the Box2D's Rope and Distance Joints
(and Mouse Joint). In Gideros there is no Rope Joint. Is there an alternative?

Is there probably some example code to check? I've found it quiet complicated
to create a elastic rope. I have been experimented with the Chain demo example.

Regards and thanks in advance,

Marc
«1

Comments

  • Are you checked "Elastic Joints" example? You can find in [Gideros Install Directory] -> Examples\Physics\Elastic Joints
  • In this example you will see one object (a sun) which will jump around.
    Some of the physics are useful but this is not what I am looking for. I
    want to create an elastic rope (like you can see in Angry birds on the
    catapult and in Cut the Rope). Here they will use "Rope Joints". See:

    http://www.raywenderlich.com/14793/how-to-make-a-game-like-cut-the-rope-part-1

    I don't know if you can do the same with distance joints. I think that Gideros
    will not support Rope Joints.

    Thanks and regards,

    Marc
  • @Dikkesnoek I understand that it can't be completed with distance joint alone, because distance joint does not provide maximum limitation, thus they will simply break or provide unrealistic physics under the load. Rope joints are usually used to limit distance joints.
    But as I have mentioned before (at least I think I have), you can use Wheel joint.

    Here is a quick video for my experiment:
    http://www.screenr.com/cxd7
    Is this any similar to what you wanted to achieve?

    I will try to post a blog post on this, just wanted to make sure that's what you wanted


  • ar2rsawseen you are brilliant! This is exactly where I was looking for :)
    Also nice one to put on AppCodingEasy. Do you have the sample code
    for me?

    Thanks a lot,

    Marc
  • ar2rsawseenar2rsawseen Maintainer
    edited December 2012
    Yes, sure here it is http://appcodingeasy.com/Gideros-Mobile/Gideros-Box2d-Chains-and-Elastic-Ropes
    Made it in kind of haste, so if anything seems wrong, just post here ;)

    Just experiment with dampening and frequencies to achieve desired result ;)

    Likes: marbolec

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks a lot. Great work!

    Marc
  • Do you think that by using the Wheel Joint you can also calculate the
    target landing position of the launched object like you showed me via
    the iforce2d link in a previous mail?

    I have switched X and Y to get the rope horizontal. I am also looking
    to move the rope objects and bodies more closer to each other (I use
    small rectangles instead of balls and edgeShapes). In that case I think
    that you can't pull the shooting object through the rope and get a
    more straight line without holes. I am still experimenting with damping
    ratios and frequencies. It's still not really clear to me how to use these
    parameters.

    Regards,

    Marc
  • @Dikkesnoek well calculating trajectory for that can be almost impossible. In this case I really think you should have another version (copy) of the world with larger time step where you simply launch the ball and record the trajectory and then project it to the user, but again it's only an idea, I don't know how that would really work out :)
  • @ar2rsawseen. Ok, I will study the shadow world copy :-* I was thinking and maybe
    you can give some advice. Isn't it better to use the slingshot example to model my
    idea? May be it's then possible to model a chain (like your example) around the object
    you want to launch. This chain is only following your object movement.

    To give you an idea what I like to make, here is a simplified drawing.

    Regards,

    Marc
    Sample_Gideros.png
    300 x 228 - 9K
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @Dikkesnoek yes that is also an option. I don't know how much chain would wrap around the object, but you have the right idea, that chain object will only serve for visual enhancement, but in reality you will set impulse to object yourself and then calculate trajectory using previous math.
    This way you could also restrict the dragging radius of your throwable object, so it won't get through the chain links from too powerful dragging
  • Thanks again, I will let you know if there is any progress.

    Marc
  • @ar2rsawseen Sorry, but I have another question. I've made the shooting object
    by using your Slingshot example. It works great, also the physics. To wrap a
    chain/rope around the object to make a visual elastic rope when dragging,
    you need another joint I think. Are you allowed to make multiple joints between
    different objects (the rope, finger, mouse) and the shooting object? In my game
    I like to place the finger anywhere on the screen and move the arm/hand, the
    rope and the shooting simultaniously. When releasing at a certain point I will
    release the object. The placement of the finger anywhere on the screen and
    shooting the object like the slingshot is already working.

    By the way, I think that I asked this before, but do you have already a game
    released I can check? With your knowledge you could make great games.

    Regards,

    Marc
  • @Dikkesnoek

    Yes you can attach how many joints you want to the object.
    Here you actually have two options:
    The easy way is to use the mousejoint/slingshot on the object you want to throw, and let the chain wrap it around by itself (by simply attaching both ends of the chain to the dummy ground object, as shown in mine example)
    The hard way is to attach both throwable object and the center of the chain to the mouse joint, but apply slingshot only to throwable object. I don't know if it's better or if needed at all, you just can try and see how it works out.

    And there is much more than a box2d knowledge needed to make great games, I'm still on my way learning ;)

    But here is my first project created with Gideros: http://jenots.com/mashballs
  • Looks great. Lots of joints? I will pick a version from the Appstore. We
    created a simple (times tables) game (Super) Kruistafels with Objective-C
    and Cocoa only.

    http://crappdesign.com/en/apps

    Now it's time for more graphical fun.

    Marc
  • New pack of Mashballs will introduce usage of joints and different new constructions, but we are also working on other physics puzzler, that will heavily rely on joints and motors :)
  • Ok nice. By the way, why does everybody use the name "ground" for
    a dummy mouse body instead of for example "mouseBody"?

    Marc
  • :)) probably because all examples are written by me
    well it might as well be air :D
  • Or the ground body will not fall down due gravity.

    I am busy to work you examples out. First I will make bodies and joints
    to move the arm and object when moving your finger anywhere on the
    screen. Then, the challenge to make al the rope/chain bodies around
    the object. I think that I will use small rectangle bodies which will overlap
    each other. I will let you know when there is positive progress.

    Marc

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
  • DikkesnoekDikkesnoek Member
    edited December 2012
    @ar2rsawseen I am trying to couple the objects. When placing the mouse
    anywhere on the screen there must be a connection to the hand and the
    object (see picture above). The hand and the yellow object must be connected
    to each other if they are one object/body. With the Weld joint, I will not work
    as expected. Al the bodies have been created before the following code.
    local function onMouseDown(event)
    	-- Create a joint at the startposition of the object.
    	local jointDef = b2.createMouseJointDef(mouseBody, objBody, startObjX, startObjY, 100000)
    	mouseJoint = world:createJoint(jointDef)
     
    	-- Create Weld joint.
    	local armJointDef = b2.createWeldJointDef(armBody, objBody, startArmX, startArmY, startObjX, startObjY) 
    	--armJointDef.collideConnected = false
            armJoint = world:createJoint(armJointDef)
     
    	-- X and Y position where the mouse has been clicked.
    	startX = event.x
    	startY = event.y
    end
  • @Dikkesnoek it seems that it should work. :-?
    what actually happens? what exactly does not work?
  • DikkesnoekDikkesnoek Member
    edited December 2012
    When I move the object by pointing the mouse somewhere, the object
    will follow. The arm will stay in place. When I release the mouse the
    arm will fall down. Strange because I gave the arm 0 density. I have the
    debugDraw activated. When I use the the Distance joint I will follow but
    not as one object. At a certain point the arm will turn around the object.
    This is what a distance joint does, and not created for this job I think.

    In the onMouseMove I do:
    -- Get the delta value when mouse has ben moved.
    local dx = event.x - startX
    local dy = event.y - startY
     
    -- Update the position of the shoe and arm.
    mouseJoint:setTarget(startObjX + dx, startObjY + dy)
    In the onMouseUp I will give the object an impulse like you explained.
    The object will shoot away as expected.

    In the onEnterFrame I will do the following:
    -- Move the sprite during animation by asking the body's current position.
    local body = objSprite.body
    local bodyX, bodyY = body:getPosition()
    objSprite:setPosition(bodyX, bodyY)
    -- Bodies work with Radians, Sprites with Degrees!
    objSprite:setRotation(body:getAngle() * 180 / math.pi)
     
    -- Update the arm.	
    body = armSprite.body
    bodyX, bodyY = body:getPosition()
    armSprite:setPosition(bodyX, bodyY)
    armSprite:setRotation(body:getAngle() * 180 / math.pi)
     
    -- When off screen, replace the object.
    if ((bodyX > 1000) or (bodyY > 700)) then
    	objSprite:setPosition(startObjX, startObjY)
    	objSprite.body:setPosition(startObjX, startObjY)
    	objSprite.body:setLinearVelocity(0, 0)
    	objSprite.body:setAngularVelocity(0)
    	world:setGravity(0, 0)
    end
    Sorry for all those questions. Maybe in the future when I am
    a physics/Lua guru I can help you out. :>

    Marc
  • Just an idea, but maybe in this case you arm might not be a physics body, but simple sprite which is dragging together with the mouse coordinates? Or it suits some other purpose than visual one?
  • DikkesnoekDikkesnoek Member
    edited December 2012
    That is indeed a good idea. I need to calculate the offset but that is easy.
    Problem is that you're sometimes looking for the complex way while the
    solution could be much simpler.

    Thanks again. Where are you from by the way? I am from the Netherlands.

    Regards,

    Marc
  • atilimatilim Maintainer
    edited December 2012
    I've implemented rope joint. I'll be available with the next version. (greetings to Latvia :) )
  • Hi Atilim,

    Great news.

    I am still experimenting with the WheelJoint. What I've found very difficult
    (and still) is to set the values of the: setSpringFrequencyHz and
    setSpringDampingRatio. I do not understand what these exactly do. Is
    there any documentation on this? Also varying parameters like Density is
    still something to learn. You need to get feeling with these physics terms.

    Regards,

    Marc
  • @Dikkesnoek well I've actually haven't seen Wheel joint before, only in Gideros :)
    But from initial experiments, the higher frequency the harder it is to stretch the rope.
    Dampening on the other hand reduces the power needed to stretch it.
    But if you set high frequency and low dampening the physics will become jigged, so frequency and dampening should be in some sort of relative ratio. You need to increase them both in some specific proportion to get a taut rope. :)
  • @ar2rsawseen In the picture above I can shoot the object and move the
    hand. I tried the wheelJoint. I created small chain elements (4x2 pixel
    rectangles) from left to right. Before the the object will be launched I've
    set the gravity to zero so the object will stay in place. When I create the
    chain of elements with the wheelJoint, the object will flow up. Is there a
    way to bend the chain nicely round the object by setting the frequency,
    damping and density. Not a quiet easy task I think.

    Regards,

    Marc
  • @Dikkesnoek by raising frequency and dampening you may restrict the chain links from stretching away one from another, but to make them round the object, you would have to make them really small, although I think that 4x2 should have been enough. :)

    Really interested in how it looks for now, can you post a screencast or screenshot of a working mechanism? :)
  • @Dikkesnoek setting frequency and dampening when using wheel joint is not easy as it looks if they are small under gravity ,each body in rope piece will have different distance. Pieces at top side have a larger distance and the bottom side have a smaller. I am waiting for next release to implement real rope effect.
Sign In or Register to comment.