isSensor causing multiple collisions?

@w.baig84 even if this is a bug or not we need to find a fix for this…
can you try doing this ?

[lua]coin1.hit = 0
coin2.hit = 0

local function onLocalCollision( self, event )
if event.other.hit == 1 then return true end
if ( event.phase == “began”) then
if ( event.other.name == “coin 1” or event.other.name == “coin 2” ) then
event.other.hit = 1[/lua]

I hope you know where to place this… :slight_smile: [import]uid: 71210 topic_id: 13795 reply_id: 51477[/import]

@renvis

Hope you don’t mind, but I am really tired!

It is almost 4 am here so I’m going to bed :slight_smile:

Will try that code in the morning…
Thanks for your help so far. [import]uid: 40538 topic_id: 13795 reply_id: 51480[/import]

oh its not an issue… :slight_smile:
good night… [import]uid: 71210 topic_id: 13795 reply_id: 51485[/import]

@renvis,

No this doesn’t work. Complex bodies are the problem.

The body needs to be made up of maximum 8 points only, in a clockwise direction. :frowning: [import]uid: 40538 topic_id: 13795 reply_id: 51578[/import]

@renvis

coin1.y = _H / coins1[rand3] gives an error:
/Users/myFiles/myFile.lua:658: bad argument #-2 to ‘insert’ (Proxy expected, got nil) [import]uid: 40538 topic_id: 13795 reply_id: 51584[/import]

I just confirmed this as well. Complex bodies trigger multiple collision events against a sensor. An event is triggered for each part of the complex body. It’s documented here: http://developer.anscamobile.com/content/game-edition-collision-detection

I take it back. It’s not a bug. But it would be nice to have a way to treat complex bodies as uni-body objects. :slight_smile: [import]uid: 27183 topic_id: 13795 reply_id: 51585[/import]

@w.baig84 it should not have any error
see this
[lua]local _W = display.contentWidth
local _H = display.contentHeight

local coins1 = {2,2.25,2.5,2.75,3}
local rand3 = math.random (2, #coins1 )
local coin1 = display.newImage(“coin.png”)
coin1:setReferencePoint(display.CenterReferencePoint)
coin1.name = “coin 1”
coin1.x = _W /2
coin1.y = _H / coins1[rand3]

for the current code you are using you don;t have to declare a table for coins1. (coins1 = {2,2.25,2.5,2.75,3})
just the below code will do the job.
[lua]local rand3 = math.random (2, 5)
coin1.y = _H / rand3 [/lua]
Happy Programming :slight_smile: [import]uid: 71210 topic_id: 13795 reply_id: 51660[/import]