joint remove problem

7 replies [Last post]
aurimas
User offline. Last seen 11 weeks 5 days ago. Offline
Joined: 1 Feb 2012

I can't destroy joint. ;/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
playerRotation = function()
         if(press)then
                player.bodyType = 'dinamic' 
                myJoint:removeSelf()
        end
        if(hit)then     
        player.bodyType = 'kinetic' 
        myJoint = physics.newJoint( "pivot", player, objektas,  player.x, player.y )    
        end
 
end
 
Runtime:addEventListener( "enterFrame", playerRotation )
 
local function onCollision( event )
        hit = true
end
 
Runtime:addEventListener ( "collision", onCollision )
 
function onTouch( event )
    press = true
    return true
end
 
background:addEventListener( "touch", onTouch)

Replies

peach pellen's picture
peach pellen
User offline. Last seen 1 day 13 hours ago. Offline
Staff
Joined: 12 Apr 2011

It looks like you are trying to destroy the joint above where it is created in the code; do you create the joint further up then recreate it again, or no?

aurimas
User offline. Last seen 11 weeks 5 days ago. Offline
Joined: 1 Feb 2012

No, I just added minimized code :) An object falls on a wheel and makes a joint to spin together and after a touch the joint should be destoyed, but it returns nil. I think i cant maintain the a reference to the joint.

aurimas
User offline. Last seen 11 weeks 5 days ago. Offline
Joined: 1 Feb 2012

local myJoint = physics.newJoint( "pivot", player, objektas, player.x, player.y )

when i make a joint outside of function(on start) it works well (destroy on tap), but then after a collision it makes a new joint with same name and that does not work.

aurimas
User offline. Last seen 11 weeks 5 days ago. Offline
Joined: 1 Feb 2012

When I create a joint in if statement I cant maintain reference to the joint outside the statemant.

peach pellen's picture
peach pellen
User offline. Last seen 1 day 13 hours ago. Offline
Staff
Joined: 12 Apr 2011

Take the local out from the joint - let me know if that helps :)

aurimas
User offline. Last seen 11 weeks 5 days ago. Offline
Joined: 1 Feb 2012

Looks like it works, thanks :)

peach pellen's picture
peach pellen
User offline. Last seen 1 day 13 hours ago. Offline
Staff
Joined: 12 Apr 2011

Not a problem, good luck with the project :)

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.