Understanding Physics
Posted: Fri Mar 20, 2009 5:50 pm
So right now I'm attempting to educate myself on the physics system. So far... weird! I've gotten a few things to work, here and there. Right now I'm trying to specifically educate myself on joints. I think I've figured out the RevoluteJoint (in as much as I can get one body to revolve around another body in a rag-doll fashion). Now I'm trying to get my head around DistanceJoint. Here's what I've come up with so far:
The two orbit each-other beautifully, but I don't really understand how or why. Mostly I'm confused about the two points I set in the DistanceJoint itself. Are those coordinates World Origin or Body Origin? Because when I set them to 500,500,100,1000 then the two points immediately move right to each-other to the outer limit of the distance I set and then... they just stop. But if I set one of them to 0,0 then I get this weird orbital pattern. I'm going to continue playing around with this, but maybe someone can shed some light on this for me?
Code: Select all
-- Orbit
function load()
world = love.physics.newWorld(1000, 1000)
bodyA = love.physics.newBody(world, 500, 500)
bodyB = love.physics.newBody(world, 100, 100)
jointA = love.physics.newDistanceJoint(bodyA, bodyB, 0,0,50,50)
jointA:setLength(100)
shapeA = love.physics.newCircleShape(bodyA, 16)
shapeB = love.physics.newCircleShape(bodyB, 16)
bodyA:setSpin(36)
end
function update(dt)
world:update(dt)
end
function draw()
love.graphics.circle(1, bodyA:getX(), bodyA:getY(), shapeA:getRadius())
love.graphics.circle(0, bodyB:getX(), bodyB:getY(), shapeB:getRadius())
end