Object slows down while attached to a distance joint.

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]

Without plug and play it’s hard to say, however I’d actually suggest checking out this sample code;
http://developer.anscamobile.com/code/orbital-rotation

See what you think of that :slight_smile: [import]uid: 52491 topic_id: 21939 reply_id: 87247[/import]

Hey, thanks for the link Peach :slight_smile:

Although I cannot use ‘pivot’ joints for I need to dynamically change the length of the joint during the game.

Also this originally started with using display groups rotating to mimic orbiting. But due to a game redesign I can’t use display groups anymore.

So the overall goal is to have multiple objects orbiting around a central object with the ability to change the distance on the fly.
So it would be nice to be able to stick with distance joints.

Thanks again. [import]uid: 40731 topic_id: 21939 reply_id: 87323[/import]

well after looking into it more I found using ‘myJoint2:getReactionForce()’ showed me that there is a constant resistance to any forces applied to the rotation.

Is there any way to set the joints reaction force to zero?

Still using distance joints by the way. [import]uid: 40731 topic_id: 21939 reply_id: 87374[/import]