isSensor causing multiple collisions?

I cannot recreate the issue that u guys are saying…
i tried this and it works perfectly fine… the began phase is triggered only once.
[lua]local gameGroup = display.newGroup()
local physics = require(“physics”)
physics.start()

function newObject()
local rand = math.random( 110 )
obj = display.newText(rand,0,0,nil,20)
obj.x = 10 + math.random( 200 )
obj.y = -100
obj.hit = 0
obj.name =rand
physics.addBody( obj, { density=0.5, friction=0.3, bounce=0} )
end
local dropobjects = timer.performWithDelay( 1000, newObject, 100 )

local groundLine = display.newRect(10, 300, 320, 100)
local function removeObject(event)
if event.phase == “began” then
print(event.other.name)
end
end

physics.addBody( groundLine, “static”,{isSensor =true})
groundLine:addEventListener(“collision”,removeObject)[/lua] [import]uid: 71210 topic_id: 13795 reply_id: 51445[/import]

Your ‘static’ object should be ‘kinematic’. [import]uid: 27183 topic_id: 13795 reply_id: 51447[/import]

Are we even talking about the same thing? I have a target object that has isSensor = true and set to ‘kinematic’. When another object that is ‘dynamic’ collides with it, my event listener that’s attached to the target fires a ‘began’ event 3 times.

How is that not a bug? [import]uid: 27183 topic_id: 13795 reply_id: 51446[/import]

@Renvis
When the player touches the coin, the coin visibility is set to false, and then an animation is spawned.
Regarding the coin tables…you sorted this for me when I was asking about blocks here :slight_smile:

https://developer.anscamobile.com/forum/2011/08/05/random-image-display-based-predefined-positions
The numbers are for the random y positions.
I need two coins because of a scrolling effect.
Anyway, it is just the collisions I am having issues with, nothing else. [import]uid: 40538 topic_id: 13795 reply_id: 51448[/import]

I don’t think this matters.
Anyway, if it is kinematic, then I get the physics crash bug.
Back to square one lol. [import]uid: 40538 topic_id: 13795 reply_id: 51450[/import]

I’ll try to produce a sample. [import]uid: 27183 topic_id: 13795 reply_id: 51451[/import]

Oh you were talking to renvis.

You guys type fast -.- [import]uid: 40538 topic_id: 13795 reply_id: 51452[/import]

That will be a good idea don… :slight_smile: [import]uid: 71210 topic_id: 13795 reply_id: 51453[/import]

@renvis

The coins are translated, the player is moved by a button which applies a tiny force.

The player is also effected by gravity. [import]uid: 40538 topic_id: 13795 reply_id: 51454[/import]

bit out of topic but its related to w.baig84’s code

for random positioning of coins I asked you to use
[lua]coin1.y = _H / coins1[rand3][/lua]

but you are using
[lua]coin1.y = _H / rand3[/lua]

this won’t give the intented result.
it will just create a random number between 2 and 5 (count of items in table coins1- #coins1).

:slight_smile: [import]uid: 71210 topic_id: 13795 reply_id: 51456[/import]

:slight_smile: Yeah, I’ll let the code do the talking. Btw, your sample does work for me as well. I’m wondering if it has to do with the complex bodies I’m using for the dynamic object. Anyways, next post I’ll have a sample. [import]uid: 27183 topic_id: 13795 reply_id: 51457[/import]

@renvis

I’m sure there was a reason why I changed it lol.

I’ll try it an see how it goes :slight_smile:
@don
I’m using Physics Editor for my dynamic object…

I’ll try using a normal shape and see if it makes any difference. [import]uid: 40538 topic_id: 13795 reply_id: 51458[/import]

that can be the key for the problem you guys are facing… if that body is created with multiple body parts then it can trigger collision event multiple times. [import]uid: 71210 topic_id: 13795 reply_id: 51461[/import]

I changed the physics to a default rectangle shape and it worked flawlessly.
Going to try making the player a sensor, and the coin a normal object.
This may work… [import]uid: 40538 topic_id: 13795 reply_id: 51462[/import]

Nope that didn’t work - even weirder thing is that even if the complex shape is turned into a sensor, if it collides with a single bodied object, then it still fires multiple times. [import]uid: 40538 topic_id: 13795 reply_id: 51463[/import]

did you try using a simple object for both colliding object ? [import]uid: 71210 topic_id: 13795 reply_id: 51466[/import]

Yes, that worked without a problem. [import]uid: 40538 topic_id: 13795 reply_id: 51468[/import]

@w.baig84 one more question just out of curiosity…

when your player touches the coin you are showing an animation of a coin moving upward right ?
is it the same coin images you are going to use for that ?
then why can’t u just animate that coin itself instead of hiding it and showing another coin ?

also you should consider removing the coin which you hide and the animated coin, other wise it will hurt your texture memory. I hope you understand what am saying… :slight_smile:
[import]uid: 71210 topic_id: 13795 reply_id: 51469[/import]

so here the sensor object is a simple body and the colliding object is a complex body so I think each body part is colliding separately with the sensor and triggers the began phase many times.

can u guys try something…put a print(event.other) inside the began phase of sensor object and see what it is printing when the complex body passes through it.

edit:oops sorry its the other way around. right ? [import]uid: 71210 topic_id: 13795 reply_id: 51471[/import]

@renvis,
Yes, that is correct.

I tried using the same image but if IIRC it was causing problems. It was a while ago.

Believe me I have tried every possible combination!
The coin I hide is used again later :slight_smile: - I have been thinking about removing the animated coin, but that is really simple to do - I have bigger problems, such as these sensors! [import]uid: 40538 topic_id: 13795 reply_id: 51473[/import]