|
|
@@ -5,24 +5,28 @@ using slider joint. Beware that slider joint loses its accuracy/stability when a
|
|
|
objects are too far away. Increasing object mass of helps with stability. --]]
|
|
|
|
|
|
local world
|
|
|
+local p1 = Vec3(1, 1.9, -1)
|
|
|
+local p2 = Vec3(-1, 2, -1)
|
|
|
+local p3 = Vec3(-1, 1.5, -1)
|
|
|
|
|
|
function lovr.load()
|
|
|
world = lovr.physics.newWorld(0, -3, 0, false)
|
|
|
- local hanger = world:newBoxCollider(vec3(1, 1.9, -1), vec3(0.1, 0.1, 0.3))
|
|
|
+ local hanger = world:newBoxCollider(p1, 0.1, 0.1, 0.3)
|
|
|
hanger:setKinematic(true)
|
|
|
- local trolley = world:newBoxCollider(vec3(-1, 2, -1), vec3(0.2, 0.2, 0.5))
|
|
|
+ local trolley = world:newBoxCollider(p2, 0.2, 0.2, 0.5)
|
|
|
trolley:setRestitution(0.7)
|
|
|
-- calculate axis that passes through centers of hanger and trolley
|
|
|
- local sliderAxis = vec3(hanger:getPosition()) - vec3(trolley:getPosition())
|
|
|
+ local sliderAxis = p1 - p2
|
|
|
-- constraint the trolley so that it can only slide along specified axis without any rotation
|
|
|
joint = lovr.physics.newSliderJoint(hanger, trolley, sliderAxis)
|
|
|
-- hang a weight from trolley
|
|
|
- local weight = world:newCapsuleCollider(vec3(-1, 1.5, -1), 0.1, 0.4)
|
|
|
+ local weight = world:newCapsuleCollider(p3, 0.1, 0.4)
|
|
|
weight:setOrientation(math.pi/2, 1,0,0)
|
|
|
weight:setLinearDamping(0.005)
|
|
|
weight:setAngularDamping(0.01)
|
|
|
- local joint = lovr.physics.newDistanceJoint(trolley, weight, vec3(trolley:getPosition()), vec3(weight:getPosition()) + vec3(0, 0.3, 0))
|
|
|
- joint:setResponseTime(10) -- make the hanging rope streachable
|
|
|
+ local joint = lovr.physics.newDistanceJoint(trolley, weight,
|
|
|
+ p2, p3 + vec3(0, 0.3, 0))
|
|
|
+ joint:setSpring(4, 0.5) -- make the hanging rope streachable
|
|
|
|
|
|
lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
|
|
|
end
|
|
|
@@ -34,6 +38,7 @@ end
|
|
|
|
|
|
|
|
|
function lovr.draw(pass)
|
|
|
+ pass:line(p1, p2)
|
|
|
for i, collider in ipairs(world:getColliders()) do
|
|
|
pass:setColor(0.6, 0.6, 0.6)
|
|
|
local shape = collider:getShapes()[1]
|