Physics line

Ok so i’m trying to implement a physical line similar to a whip. I know I am doing something wrong with the joints because the rest of the code was tested and on top of that it’s peaches code so you know it works :slight_smile:

As it is currently it sort of just explodes after the line is drawn.

[lua]local lines = {}
local myLines = {}
local prevX,prevY

require ( “physics” )
physics.start()
physics.setGravity( 0, 7.5 )
physics.setDrawMode(“normal”)

local i = 1
local j = 0
local function drawLine(e)
if “began” == e.phase then
myLines[i] = {}
prevX = e.x
prevY = e.y
elseif “moved” == e.phase then
if prevX then
print(#myLines[i])
myLines[i][#myLines[i] + 1] = display.newLine(prevX,prevY,e.x,e.y)
myLines[i][#myLines[i]].width = 3
physics.addBody(myLines[i][#myLines[i]], “static”, {density = 0.0, friction = 0.0, bounce = 0.0})
if(not(#myLines[i] == 0))then
physics.newJoint( “pivot”, myLines[i][#myLines[i]], myLines[i][#myLines[i]-1],1,1 )
end
end
prevX = e.x
prevY = e.y
elseif “ended” == e.phase then
prevX = nil
prevY = nil
j = #myLines[i]
while(j >= 1) do
myLines[i][j].bodyType = “dynamic”
j = j - 1
end
i = i + 1

end
end
Runtime:addEventListener(“touch”,drawLine)
[lua] [import]uid: 9484 topic_id: 16921 reply_id: 316921[/import]