I'm trying to constrain a body to a line segment, which lies between two other bodies. I'm calling this constraint a "rail". Here is a drawing of what I'm trying to do:
The green circle should move freely along the green arrows, and should not be able to move at all along the red arrow.
So far I'm doing something like this:
Code: Select all
function AttachToRail(rail, bodyB)
local endX = rail.StartBody:getX()
local endY = rail.StartBody:getY()
local axisX = rail.BodyEnd:getX()
local axisY = rail.BodyStart:getY()
local joint = Physics.newPrismaticJoint(
rail.BodyStart, bodyB,
endX, endY,
axisX, axisY
)
end
Which works alright when the "rail" doesn't move. If it does move, the attached body just keeps moving along the axis that was originally designated. Looking at the docs for PrismaticJoints
love2d.org/wiki/PrismaticJoint, I don't see any way of updating the axis.
Does anyone have any ideas as to how I can accomplish my goal? Am I just doing something wrong? Any help would be appreciated. Thanks for reading