Detect collision location between two objects on a Non physics collision

Hi 

  Sorry for asking such a question but I have searched here and google for this but I am not getting the correct search results when I do.

  ** EDIT **

   Also I apologise for the title , it sounded right in my head but now that I look back at it, it does not really mean what I am after .So sorry for those of you who have read the title thinking one thing and then reading the post realising that I am meaning something slightly different :( 

Currently my project consists of a player object which when making contact with certain other objects , after so many collisions, the other objects are destroyed.

 That part I have got working but what I am trying to do is only one part of the player object needs to make contact with the other objects for this to work.

 My collision code is from this page - > https://coronalabs.com/blog/2013/07/23/tutorial-non-physics-collision-detection/ 

  Using this method :

local function hasCollided( obj1, obj2 ) if ( obj1 == nil ) then -- Make sure the first object exists return false end if ( obj2 == nil ) then -- Make sure the other object exists return false end local left = obj1.contentBounds.xMin \<= obj2.contentBounds.xMin and obj1.contentBounds.xMax \>= obj2.contentBounds.xMin local right = obj1.contentBounds.xMin \>= obj2.contentBounds.xMin and obj1.contentBounds.xMin \<= obj2.contentBounds.xMax local up = obj1.contentBounds.yMin \<= obj2.contentBounds.yMin and obj1.contentBounds.yMax \>= obj2.contentBounds.yMin local down = obj1.contentBounds.yMin \>= obj2.contentBounds.yMin and obj1.contentBounds.yMin \<= obj2.contentBounds.yMax return (left or right) and (up or down) end

and so I have tried to change the results of this but as I am trying to only have contact from the players left and lowest point no combination seems to work from this method/function.

** edit **

Also if this makes any difference - the player object is moved by dragging.

Furthermore at some I will need to figure out how to “flip” the players object so that the left side of the object becomes the right side and therefore the collision detection would need to be able to handle this also

Thanks

TimCS

Hi again

  I have another idea based on this question, if an object collision point cannot be determined, is it possible to make an object up from several other objects (or in my case images created as objects) and then still treat each object individually as well as one. 

So when the grouped object is dragged it acts as one but when one part makes a collision that is treated separately. Now I have looked at group objects but if the “design” of the object is a varied shape thin one end and thicker at the other, then I need to know for example that the thicker end has made a collision so I could not see how a group object would work that way especially if the collision with the thicker end is protruding out from the other part of the object pieces. To explain that better think of a broom and only when the brush part is making contact does the game want to act on this.

Thanks

TimCS 

Thought I would come back on this as I think I have got it to work with my object. I have used the following code :

local function hasCollidedCircle( obj1, obj2 ) if ( obj1 == nil ) then -- Make sure the first object exists return false end if ( obj2 == nil ) then -- Make sure the other object exists return false end local dx = obj1.x - obj2.x local dy = obj1.y - obj2.y local distance = math.sqrt( dx\*dx + dy\*dy ) local objectSize = (obj2.contentWidth/2) + (obj1.contentWidth/2) if ( distance \< objectSize ) then return true end return false end

and then changed it for my player object to this :

local function hasCollidedCircle( obj1, obj2 )&nbsp; &nbsp; if ( obj1 == nil ) then &nbsp;-- Make sure the first object exists &nbsp; &nbsp; &nbsp; &nbsp; return false &nbsp; &nbsp; end &nbsp; &nbsp; if ( obj2 == nil ) then &nbsp;-- Make sure the other object exists &nbsp; &nbsp; &nbsp; &nbsp; return false &nbsp; &nbsp; end &nbsp; &nbsp; local dx = obj1.x - obj2.x &nbsp; &nbsp; local dy = obj1.y - obj2.y &nbsp; &nbsp; local distance = math.sqrt( dx\*dx + dy\*dy ) &nbsp; &nbsp; local objectSize = (obj2.contentHeight/2) + (obj1.contentHeight/2) &nbsp; &nbsp; if ( distance \< objectSize ) then &nbsp; &nbsp; &nbsp; &nbsp; return true &nbsp; &nbsp; end &nbsp; &nbsp; return false end

 because the part of the player object that I need to have the collision with is the part that represents the highest part of the object this appears to be working now. So I hope when I figure out how to flip or switch the object to fact the other way, in theory this should still work.

Thanks

TimCS 

Hi again

  I have another idea based on this question, if an object collision point cannot be determined, is it possible to make an object up from several other objects (or in my case images created as objects) and then still treat each object individually as well as one. 

So when the grouped object is dragged it acts as one but when one part makes a collision that is treated separately. Now I have looked at group objects but if the “design” of the object is a varied shape thin one end and thicker at the other, then I need to know for example that the thicker end has made a collision so I could not see how a group object would work that way especially if the collision with the thicker end is protruding out from the other part of the object pieces. To explain that better think of a broom and only when the brush part is making contact does the game want to act on this.

Thanks

TimCS 

Thought I would come back on this as I think I have got it to work with my object. I have used the following code :

local function hasCollidedCircle( obj1, obj2 ) if ( obj1 == nil ) then -- Make sure the first object exists return false end if ( obj2 == nil ) then -- Make sure the other object exists return false end local dx = obj1.x - obj2.x local dy = obj1.y - obj2.y local distance = math.sqrt( dx\*dx + dy\*dy ) local objectSize = (obj2.contentWidth/2) + (obj1.contentWidth/2) if ( distance \< objectSize ) then return true end return false end

and then changed it for my player object to this :

local function hasCollidedCircle( obj1, obj2 )&nbsp; &nbsp; if ( obj1 == nil ) then &nbsp;-- Make sure the first object exists &nbsp; &nbsp; &nbsp; &nbsp; return false &nbsp; &nbsp; end &nbsp; &nbsp; if ( obj2 == nil ) then &nbsp;-- Make sure the other object exists &nbsp; &nbsp; &nbsp; &nbsp; return false &nbsp; &nbsp; end &nbsp; &nbsp; local dx = obj1.x - obj2.x &nbsp; &nbsp; local dy = obj1.y - obj2.y &nbsp; &nbsp; local distance = math.sqrt( dx\*dx + dy\*dy ) &nbsp; &nbsp; local objectSize = (obj2.contentHeight/2) + (obj1.contentHeight/2) &nbsp; &nbsp; if ( distance \< objectSize ) then &nbsp; &nbsp; &nbsp; &nbsp; return true &nbsp; &nbsp; end &nbsp; &nbsp; return false end

 because the part of the player object that I need to have the collision with is the part that represents the highest part of the object this appears to be working now. So I hope when I figure out how to flip or switch the object to fact the other way, in theory this should still work.

Thanks

TimCS