Community Forum

raycastAll raycastClosest problem

Forum Overview >> Farming Simulator 2011

CategoryFarming Simulator 2011
Created30.10.2010 14:52


Ellinor Ström (Unknown) 30.10.2010 15:14
I have a big problem with raycasting, i tried both raycastAll and raycastClosest. It finds some trailer and other report back target == nil, it finds my containers for example which are trailers, it finds the standard ingame medium tipper. But it returns target == nil on the standard ingame Big and Small tippers. I don't have a clue what's going wrong, or why it returns such unreliable data!

function ULW:load(xmlFile)
self.findTrailerRaycastCallback = ULW.findTrailerRaycastCallback;
self.trailerFound = 0;

self.trailerPosition = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.trailerPosition#index"));
end;

function ULW:update(dt)
self.trailerFound = 0;
local x,y,z = getWorldTranslation(self.trailerPosition);

raycastAll(x, y, z, 0, -1, 0, "findTrailerRaycastCallback", 8, self);
local target = g_currentMission.objectToTrailer[self.trailerFound];
end;

function ULW:findTrailerRaycastCallback(transformId, x, y, z, distance)
if getUserAttribute(transformId, "vehicleType") == 2 then
self.trailerFound = transformId;
end;

return false;
end;



Stefan Geiger - GIANTS Software 01.11.2010 09:38
If implement the findTrailerRaycastCallback, it will stop the searching after the first object was hit (which is the same then as raycastClosest). This might be a trailer object, or anything else. For example the trailers do have a "exactFillRootNode" just a little above the trailer, which however is not in objectToTrailer. Mostly you will hit this object first.

So what you need to do, is let the raycast go, until you find your trailer.

You can do this by returning "true" in the callback function, if it is not a trailer. Then it will continue.

So your function might look like this:

function ULW:findTrailerRaycastCallback(transformId, x, y, z, distance)
if getUserAttribute(transformId, "vehicleType") == 2 then
self.trailerFound = transformId;
return false;
end;

return true;
end;

Ellinor Ström (Unknown) 01.11.2010 21:04
OOh, *facepalm* that's about the only thing i have not tried, didn't think about the return.

Thank you Stefan!



Note: Log in to post. Create a new account here.