event.x, event.y

Why are the event.x and event.y values always 0?

local function testDragDynamicBody() local function touch(e) if (e.phase == "began") then e.target.hasFocus = true display.currentStage:setFocus(e.target) e.target.prev = e return true elseif (e.target.hasFocus) then e.target.x, e.target.y = e.target.x+(e.x-e.target.prev.x), e.target.y+(e.y-e.target.prev.y) e.target.prev = e if (e.phase == "moved") then else e.target.hasFocus = nil display.currentStage:setFocus(nil) end return true end return false end local function collision(e) dump(e) return false end local function addBody(n,x,y,w,h) local a = display.newRect( x, y, w or 100, h or 10 ) a.name = n physics.addBody( a, "dynamic", { isSensor=true } ) a:addEventListener( "touch", touch ) a:addEventListener( "collision", collision ) return a end local a, b = addBody( "a", 100, 100 ), addBody( "b", 400, 100 ) Runtime:addEventListener( "collision", collision ) end testDragDynamicBody()

(Please excuse the terrible touch handling.)

I did the tests and both event.xche event.y work. Maybe we need more information …

This is what I see:

https://youtu.be/l–NGJ1-LPU

@horacebury, can  you share your test project with us? Dropbox/Google Drive link would be great.

https://www.dropbox.com/sh/7wkcf2hn1q5iliq/AAAYs7JohFgF5qeUbxPaOYawa?dl=0

Hi @horacebury,

I did some testing on this. Unfortunately, it appears that it will always be 0 if one (or both) bodies are sensors. If you make them non-sensors, the reported x/y collision point is returned perfectly (well, on the “began” phase, but still 0 on the “ended” phase as is noted in the documentation).

I will add a point on the documentation along these lines soon.

Brent

Thanks, Brent. That’s not great news for my scenario but I understand why that is likely. I am still hoping it’s an option within the internal setup of Box2D and not immutable. Good to have the docs updated, of course.

Hi Matt,

If this doesn’t appear to actually be a “Box2D thing,” based on their official resources, please let me know and I’ll try to explore if Corona is doing some type of override that it shouldn’t be…

Thanks,

Brent

pretty sure this is a “Box2D thing”, as sensors only detect contact, they don’t technically collide.  (notwithstanding that corona’s event is named “collision” no matter the body’s sensor status)  sensors don’t have collision response, so manifolds are never created, so collision points/normals are never calc’d, because they’re never needed for collision response.  so i’d be amazed if corona were somehow able to report “sensor collision details”.

I did the tests and both event.xche event.y work. Maybe we need more information …

This is what I see:

https://youtu.be/l–NGJ1-LPU

@horacebury, can  you share your test project with us? Dropbox/Google Drive link would be great.

https://www.dropbox.com/sh/7wkcf2hn1q5iliq/AAAYs7JohFgF5qeUbxPaOYawa?dl=0

Hi @horacebury,

I did some testing on this. Unfortunately, it appears that it will always be 0 if one (or both) bodies are sensors. If you make them non-sensors, the reported x/y collision point is returned perfectly (well, on the “began” phase, but still 0 on the “ended” phase as is noted in the documentation).

I will add a point on the documentation along these lines soon.

Brent

Thanks, Brent. That’s not great news for my scenario but I understand why that is likely. I am still hoping it’s an option within the internal setup of Box2D and not immutable. Good to have the docs updated, of course.

Hi Matt,

If this doesn’t appear to actually be a “Box2D thing,” based on their official resources, please let me know and I’ll try to explore if Corona is doing some type of override that it shouldn’t be…

Thanks,

Brent

pretty sure this is a “Box2D thing”, as sensors only detect contact, they don’t technically collide.  (notwithstanding that corona’s event is named “collision” no matter the body’s sensor status)  sensors don’t have collision response, so manifolds are never created, so collision points/normals are never calc’d, because they’re never needed for collision response.  so i’d be amazed if corona were somehow able to report “sensor collision details”.