Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
limiting revolute joint question — Gideros Forum

limiting revolute joint question

mykyl66mykyl66 Member
edited November 2011 in Announcements
I am using this code and have two objects attached. I am now trying to limit the rotation but keeping getting a nil value for setlimits.

Any ideas where I am obviously going wrong.

local myJoint = b2.createRevoluteJointDef(myMan.body, myArm.body, randX-50 , randY)
myJoint:setLimits(1,1)
myJoint:enableLimit(true)
--local myJoint = b2.createDistanceJointDef(myMan.body, myArm.body, randX, randY, randX-50, randY)
myworld:createJoint(myJoint)

Mike
What would you do for your other half?

http://www.sharksoupstudios.com

Comments

  • atilimatilim Maintainer
    edited November 2011
    Joint definition tables are just ordinary Lua tables without any functions or metatable. Therefore you just set the fields of them and pass the joint definition table to the createJoint function.

    After you create your joint definition table with createXXXJointDef function, you directly set the limits
    local myJointDef = b2.createRevoluteJointDef(myMan.body, myArm.body, randX-50 , randY)
    myJointDef.enableLimit = true
    myJointDef.lowerAngle = angle1 * math.pi / 180
    myJointDef.upperAngle = angle2 * math.pi / 180
    and then create your joint
    local myJoint = myworld:createJoint(myJointDef)

    Optionally, you can set the limits after creating the joint:
    myJoint:enableLimit(true)
    myJoint:setLimits(angle1 * math.pi / 180, angle2 * math.pi / 180)
    (I know it's not very clear at first sight :) )
  • Right. I think I understand it now. :)

    Mike
    What would you do for your other half?

    http://www.sharksoupstudios.com
Sign In or Register to comment.