Removing Joint Physics on collision?

Hey I have a question how do I remove joints physics when collision is detected like removing parts I would really like to know here is an example code of physics joint

[code]display.setStatusBar( display.HiddenStatusBar )

require “physics”
physics.start()
–physics.setGravity(0, 1.5)
physics.setDrawMode(“hybrid”)

–Determine Device Size
local disw = display.contentWidth
local dish = display.contentHeight

local car = display.newGroup()

–Create The Car
local car_body = display.newRect(0, -20, 102, 40)
car_body:setFillColor(100,75,75)

local rear_weld = display.newRect(14, 20, 4, 4)
local front_weld = display.newRect(84, 20, 4, 4)
rear_weld:setFillColor(100,50, 50)
front_weld:setFillColor(100, 50, 50)

local car_rear_wheel = display.newCircle( rear_weld.x, rear_weld.y, 15 )
local car_front_wheel = display.newCircle( front_weld.x, front_weld.y ,15 )
car_rear_wheel:setFillColor(25,128,25)
car_front_wheel:setFillColor(25,25,200)

–Add An Environment
local floor = display.newRect(0, dish-10, disw,dish )
local lwall = display.newRect(0, 0, 0,dish )
local rwall = display.newRect(disw,0,disw,dish)
local ramp = display.newLine(0,dish-40,disw,dish-10)
local rshape = {0,0,disw,30}
ramp.width = 3

–Apply The Physics
physics.addBody(floor,“static”, {friction=0.5})
physics.addBody(lwall,“static”, {friction=0.5})
physics.addBody(rwall,“static”, {friction=0.5})
physics.addBody(ramp,“static”,{friction=1,shape=rshape})
physics.addBody(car_body,{density=0,friction=0,bounce=0})
physics.addBody(rear_weld,{density=0,friction=0,bounce=0})
physics.addBody(front_weld,{density=0,friction=0,bounce=0})
physics.addBody(car_rear_wheel,{density=2,friction=3,bounce=0,radius=15})
physics.addBody(car_front_wheel,{density=2,friction=3,bounce=0,radius=15})

local rear_weld_joint = physics.newJoint(“weld”, rear_weld, car_body, rear_weld.x, rear_weld.y)
local front_weld_joint = physics.newJoint(“weld”, car_body, front_weld, front_weld.x, front_weld.y)

local rear_wheel_joint = physics.newJoint(“pivot”,car_rear_wheel,rear_weld,rear_weld.x, rear_weld.y)
local front_wheel_joint = physics.newJoint(“pivot”,front_weld,car_front_wheel,front_weld.x, front_weld.y)

–Keep The Wheels Separated
local wheel_distance_joint = physics.newJoint(“distance”,car_rear_wheel, car_front_wheel, car_rear_wheel.x, car_rear_wheel.y, car_front_wheel.x, car_front_wheel.y)

–Populate The Scene
car:insert(lwall)
car:insert(rwall)
car:insert(floor)
car:insert(ramp)
car:insert(car_body)
car:insert(car_rear_wheel)
car:insert(car_front_wheel)

return car [/code]

Now from this example how can I remove a joint when collision is detected and add points to it. Also how would I remove an entire joint system. This a plug and play so you can see it

Please help is appreciated thanks :slight_smile: [import]uid: 17058 topic_id: 21607 reply_id: 321607[/import]

Collision detection I think you know how to do, if not it is covered in Corona for Newbies Part 4.

To remove the joint, do;
[lua]jointName:removeSelf()[/lua]

Points would then be added in the collision function, eg;
[lua]score=score+1[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 21607 reply_id: 85750[/import]

@peach having problem removing joint this is how I have it

local function move () rear\_wheel\_joint:removeSelf() end Runtime:addEventListener("touch", move)

I end up getting an error [import]uid: 17058 topic_id: 21607 reply_id: 85773[/import]

What are you trying to do?

Every single time the screen is touched OR released this will fire. There is only one joint and you’re calling the remove twice anytime the screen is touched and released.

That is no good. [import]uid: 52491 topic_id: 21607 reply_id: 85779[/import]

i’m trying to remove a joint [import]uid: 17058 topic_id: 21607 reply_id: 85780[/import]

so how do I do I [import]uid: 17058 topic_id: 21607 reply_id: 85781[/import]

Read your code;

[lua]local function move ()
rear_wheel_joint:removeSelf()
end
Runtime:addEventListener(“touch”, move)[/lua]

This code says that every time there is a touch or a release anywhere on the screen that the joint should be removed.

Now, how exactly would that work? There is one joint called rear_wheel_joint and it can only be removed once.

Ergo, you should only try to remove it ONCE. Doing it constantly will fail.

It would be better not to use a Runtime at all but if you must, remove it after first call;

[lua]local function move ()
Runtime:removeEventListener(“touch”, move)
rear_wheel_joint:removeSelf()
end
Runtime:addEventListener(“touch”, move)[/lua]

Is this making sense to you?

Peach :slight_smile: [import]uid: 52491 topic_id: 21607 reply_id: 85784[/import]