Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Breaking the Wheel Joint — Gideros Forum

Breaking the Wheel Joint

DikkesnoekDikkesnoek Member
edited March 2013 in General questions
Hi,

I am back to work on my game. I still like to make a catapult/slingshot based game. I am
no trying to implement the Wheel Joint (instead of the rope/chain stuff) like explained in
the "Elastic Joint" example. I also use a Mouse Joint. I case of the mouse joint I can place
my finger anywhere on the screen.

What's still not working is that I want to break (destroy?) the wheel joint and let the object
(like the the sun from the example) shoot away when it crosses the centerpoint of the wheel
(so it will not bounce back). I don't know if I can use the physics from the wheel joint def to
let it shoot or that I need to apply a new applyLinearImpulse.

Thanks,

Marc

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Well you could on enter frame (basically in the loop where you update sprite positions to body positions) check for specific's body position (if it crosses the centerpoint) and destroy joint using b2.World:destroyJoint(joint) method.
    Can't tell if you'll need additional impulse, thats based on settings you have etc, but it would be rather easy to apply it in same place in code if needed (as you can get current linear velocity vector and multiply it by some factor to apply as impulse) ;)
  • Hi ar2rsawseen,

    Thanks again for you quick response. I did what you explained. I have
    two joints, the mouseJoint and the wheelJoint. It looks if I destroy the
    mouseJoint before the wheelJoint, the wheelJoint will be destroyed too
    and I will get the message: "Joint is already destroyed." So I think that
    the wheelJoint will be destroyed to early.

    Regards,

    Marc

    Dislikes: JuanZambrano

    +1 -1 (+0 / -1 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    It's strange it should not be destroyed automatically unless you destroy the body it was attached to.
    But yes, this is a problem in box2d that you can't destroy something twice and you can't check if it was destroyed so I usually safe one property to joints (can be also applied to body's), like joint.isDestroyed = false

    So everythime before destroying it I check
    if not joint.isDestroyed then
        joint.isDestroyed = true
        --destroy joint here
    end
  • Oh, I think that the "Elastic Joints" demo is based on a distance joint.
    I think that I am not completely understand the joints. In the example
    it looks that it acts more like a wheel joint. How is it possible that the
    distance can be variable in a distance joint? The sun in the demo can
    go through the ground point.

    Regards,

    Marc
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @Dikkesnoek the idea of distance joint is to limit the minimal distance, whereas the idea of rope joint is to limit maximal distance.

  • DikkesnoekDikkesnoek Member
    edited March 2013
    Ok, I'll get it. I found a nice article about creating ropes:

    http://www.cocos2d-iphone.org/archives/1112

    It's called "Verlet Integration". Never heard it before.
    Hope it's easy to implement in Gideros LUA.

    Thanx,

    Marc
Sign In or Register to comment.