Alpha?) No.. I'm talking about b2.World:rayCast(x1, y1, x2, y2, listener, data) I need to know which object was crossing ray. how this parameter is considered? sorry for my english)
yes, I understand that, but how exactly do I callback this the first parameter?
function rayfunc(event) if event."First parameter" == box then ...... elseif."First parameter" == crate then .... end end ray = self.world:rayCast(0, 0, 200, 200, rayfunc)
I do not understand how to read its "first parameter"..
So, for example, you have a variable world where you have world instance and some kind of box2d object ball. You want to project raycast on x axis through all the screen and get fixture if there is one
local x, y = ball:getPosition()local screenWidth = application:getContentWidth()local raycastCallback function(fixture, hitX, hitY, vectX, vectY, fration)--so if this function is called, it means we hit some kind of object--and it's fixture is stored in first variable we named "fixture"--so we can for example get bodylocal body = fixture:getBody()end--now we add callback function for projected raycast--Parameters:--object x coordinate--object y coordinate--projection vector on x axis--projection vector on y axis--callback function
world:rayCast(x, y, x+screenWidth, y, raycastCallback)
I use rayCastCallback function to check collision between a fixed body and a set of bodies on the left, returning 1.
A list of collision points is built but this list is not ordered by axis X (sense of raycast from fixed body to the left side), it seems to be randomized.
Anyway I can ordered this list by axis X but I believe raycast will do it the job.
Well it should be ordered by the increasing distance from your starting point to the raycasting direction, which might not always be increasing with the x axis values (depending on your direction).
Comments
»Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
I need to know which object was crossing ray. how this parameter is considered?
sorry for my english)
https://play.google.com/store/apps/details?id=com.uglygames.slug
First one is the fixture hit by the ray
function rayfunc(event)
if event."First parameter" == box then
......
elseif."First parameter" == crate then
....
end
end
ray = self.world:rayCast(0, 0, 200, 200, rayfunc)
I do not understand how to read its "first parameter"..
https://play.google.com/store/apps/details?id=com.uglygames.slug
So, for example, you have a variable world where you have world instance and some kind of box2d object ball. You want to project raycast on x axis through all the screen and get fixture if there is one
https://play.google.com/store/apps/details?id=com.uglygames.slug
I mean I defined the function:
list = {}
function raycastCallback (fixture, hitX, hitY, vectX, vectY, fration)
local body = fixture:getBody()
list[#list + 1] = body
end
but list is not sorted in the sense of the raycast. Is it correct?
A list of collision points is built but this list is not ordered by axis X (sense of raycast from fixed body to the left side), it seems to be randomized.
Anyway I can ordered this list by axis X but I believe raycast will do it the job.
if its not, maybe there is some other problem
local left = -2000
-- Left hits
self.world:rayCast( v:getX(), v:getY(), v:getX() + left, v:getY(), self.raycastCallback, self)
where v is a sprite object and self.list is the bodies list and contains all bodies in the raycast trajectory but sometimes not ordered.
I suppose it is a behaviour of box2d engine.