Attach a line to object by touch, and release by touch?

I am having a hell of a time trying to figure something out.
I watched this video by cheetomoskeeto and bought his code for physics demonstrations.
Here is a video for those that are interested:
http://www.youtube.com/watch?v=hpa48QGFKsU
After watching this, I wanted to cook up some code for a physics game idea I had.

Basically it goes something like this:
This is plug n play code, I’m using system generated shapes:

--let's say I have a box   
  
local physics = require("physics")  
physics.start()  
physics.setScale( 60 )  
physics.setGravity( 0, 9.8 )  
physics.setPositionIterations(8)  
  
--Here is the star of the show, the "Actor"  
  
local actor = display.newRect( 150, 90, 50, 50 )  
actor:setFillColor(255,255,255)  
physics.addBody( actor,"dynamic", { density=1, friction=3, bounce=0.3, isGround = true } )  
actor.rotation = 0  
--I have a platform  
  
local rect1 = display.newRect( 260, 150, 200, 50 )  
rect1:setFillColor(200,10,90)  
physics.addBody( rect1,"static", { friction=3, bounce=0.3, isGround = true } )  
rect1.rotation = 0  
--And I have a bottom of a level  
  
local bottom = display.newRect( 0, 480, 640, 40 )  
bottom:setFillColor(80,10,90)  
physics.addBody( bottom,"static", { friction=3, bounce=0.3, isGround = true } )  
bottom.rotation = 0  

Ok if you run the code (i normally do this in Mac, but im on a windows box right now) You will see the white box fall and hit the purple ground.

That’s fine and dandy, but what I would like and I am researching it now but as a beginner I am ultra confused on trying to do what I am about to ask:
Here is the scoop - I want to attach a fixed length line (like a rope) that comes out of the box and attaches to any physics object, unless I don’t want it to. Think along the terms of spiderman type of thing.

I want to have a line, a piece of string a chain (whatever) that only shows up when I touch a platform, object or whatever and then be able to release by touching anywhere that IS NOT a physics body, OR be able to touch another physics body and attach to that, only given that it is within the amount of pixels for the length of the string, or chain, line, rope whatever.

Things I know:

I know I will have to put a touch event on my actor or I would have to put a touch even on, um a platform or a group of physics bodies that are allowed to be attached to.

I would then have to have some kind of “if physics body is within X pixels, then allow attachment of line if not, then no”

Then I would have to have some kind of release logic like “if touch is on a non physics object then string dissapears back into the white box”
I apologize profusely right now, as I have figured out how to weld, and do rotations and animations etc but this thing I want to do is WAY over my head right now lol. I’ve pretty much (thanks to everyone on this forum, peach pellen’s techority site, learningcorona.com, mobil tuts + , cheetomoskeeto’s youtube, etc etc) gotten most “features” i want in my game.

I am not asking for someone to just put code on screen and me plug it in and it works (although I won’t complain). I really want to learn how to do this so if you have hints, or something like that I am all ears :slight_smile: :slight_smile: :slight_smile: :slight_smile:
Thanks a bunch, so many people have helped me out. I’ve compiled a list of those people and they will be part of my “Credits” section of my game when I release it in 64 days (the deadline to get my binaries to apple).

-ng [import]uid: 61600 topic_id: 13302 reply_id: 313302[/import]

* gentle bump*

Ive tried various things, I’m stumped on this one :frowning: [import]uid: 61600 topic_id: 13302 reply_id: 49349[/import]

bump with a kinder, gentler bump :slight_smile: [import]uid: 61600 topic_id: 13302 reply_id: 56966[/import]