I’m trying to set up an object to orbit around another by using a distance joint. I use object:applyForce to move the orbiting object, but I’ve noticed the speed slowly drops down over time. When I don’t have the object attached to the joint the speed never drops.
Am I missing something, is the joint somehow slowing the object down?
Here’s my code so far.
[code]
W = display.contentWidth
H = display.contentHeight
local physics = require( “physics” )
physics.start()
physics.setDrawMode( “hybrid” )
physics.setGravity( 0, 0 )
core1 = display.newImageRect(“images/planet3.png”, 30, 30)
physics.addBody( core1, “static”, {radius=8,density = 1})
core1.x = W/2; core1.y = H/2
planet2 = display.newImageRect( “images/planet1.png”, 40, 40)
physics.addBody( planet2, “dynamic”, {radius=4,density = 1})
planet2.x = W/2; planet2.y = H/4
planet2:applyForce( 3, 0, planet2.x, planet2.y )
myJoint2 = physics.newJoint( “distance”, core1, planet2 , core1.x, core1.y, planet2.x, planet2.y )
local function displaySpeed()
vx, vy = planet2:getLinearVelocity()
speed = math.sqrt(vx*vx+vy*vy)
print(speed)
end
Runtime:addEventListener(“enterFrame”, displaySpeed)
local function moveStuff(e)
if e.phase == “began” then
function moveIN()
myJoint2.length = myJoint2.length-2
end
Runtime:addEventListener(“enterFrame”, moveIN)
elseif e.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, moveIN)
end
end
Runtime:addEventListener(“touch”, moveStuff) [import]uid: 40731 topic_id: 21939 reply_id: 321939[/import]
[import]uid: 52491 topic_id: 21939 reply_id: 87247[/import]