Snapping objects and issues with groups

Have been trying every possible thing I can think of with this for ages now but said will try the forum one last time to see if people have any inspiration I havent thought if.

I have two objects that I need to snap together when they collide but only if they pass certain criteria..

They will be two bits of pipe. I have two different types of pipe..a straight piece and a curved piece. They can be dragged around the screen and tapped to rotate them by 90 degrees each tap.

So obviously I need to snap the ends together. So some of the issues, I need to make sure that they only attach if they are end to end, not at 90 degrees to each other, eg two straight pipes facing the same way is fine but at 90 degrees to each other isnt.

So my idea was to put a point at each end of the pipes and use it as a way to run som checks, first on collision make sure the pipes are facing the same direction (I get the objects rotation and set a variable based on this eg 0 degrees = 1, 90 deg = 2, 180 deg =3, 270 and 360 deg = 4). So think of it like a compass and I can tell at which point the 2 dots are on each pipe. So all I then need to do is make sure that I run a check on collision and only allow them to snap if they are at opposites to each other, so a 1 can join a 3 and a 2 to a the right of one pipe can join to the left of another, but two right ends or left ends cant join. This basically covers any effort of overlapping or attaching any of the pipes at the wrong end or making an incorrect snap.

Thats all fine in theory so to do it I went and amade my pipe object and in that I used the physics editor to make the two kinds of pipe. I have 2 parallel lines for the straight pipe and then 2 curved lines for the bend pipe and then both have a display image depending on the pipe type.

I then have 2 points that I put at either end of the pipe in the centre of its y axis.

I then assign the 3 objects to a group and return that group. When I then create a pipe in the game it uses this pipe object and creates the pipe based on the type paramter and assigns the two dots.

Initially I was having issues when I rotated it as the two dots were rotating on their own CentreReferencePoint and not following the pipes rotation. I managed to fix that by offsetting the X and Y ref as required so it rotates properly.

However all of this is causing various problems.

1: The dots werent physics bodies so they wouldnt detect collision. So I then went and made another opject that was a sensor and static and then added a pivot joint to that and the dot so they were stuck together. They all rotate as meant to but something odd is happening. I have a print to tell me when the dot collides with anything but the only collision it seems to detect is the collision with the joint after it rotates and the joint follows and snaps to its location.

2: The pipe object even though it is static as it should be (tested with a print bodytype) no longer acts static, ie the ball falls through it instead of passing through it.

I know from reading various posts there are issues with groups and rotation and collision etc. I have got around some of them by cycling through the group and rotating each child individually but then as I said there are other issues happening.

Has anyone got an easier or better way to go about this or a solution to the issues above. Sorry for the long explanation but its hard to explain the specifis without going into the details.

Ideally I want the pipes to snap to each other but as i said only if the they are meant to logically snap. So a left end snaps to a right etc.

On a seperate note I have physics paused in the game as I have a ball in place ready to fall and other objects like planks that are all set to fall once you press play (which unpauses the physics) so something else I only realised after was that it wont actually detect the collisions unless the physics is actually on..I cant really get around this as I dont want the ball to fall or the other objects until I start the game - (Think Bubble Ball) but then the collision cant be detected till I turn physics back on..any suggestions on that would be cool too but not as vital.

views:1296 update:2012/1/10 9:16:25
corona forums © 2003-2011