3dreamengine/3DreamEngine

Raycast method cast params

CrossroadInTheVoid opened this issue · 3 comments

raytrace:cast(object, origin, direction) is good not for all situations as I understand.
Sometimes it's better to cast from one point to another one and get first or all intersections.
For example, I use construction like this in old version of 3Dreamengine to detect mouseclicks at mobs:

local _pos = dream:pixelToPoint(vec3(mX, mY, 0));
local _point = dream:pixelToPoint(vec3(mX, mY, length_of_cast_ray));
local _segment = collision:newSegment(_pos, _point);

for i = 1, #_mobs do	
  local _collider = _mobs[i][1]:GetCollider ();
  if _collider and collision:collide(_segment, _collider, true) then
     …
  end;
end;

--Collider can be created for every mob like:
local _collider = collision:newMesh (object);

As you can see I use vec3 points (pixelToPoint returns them) for raycast, using an object here can be not so good. Of course I can raycast all mobs in a cycle and use mobs like first param for raytrace cast. But for some reason this is not the best variant.

So, the question is: is it possible to add vec3 --> vec3 raycast method with limitation of the cast distance? It's good to get first hited object, or all hited objects in an array.

Sorry for disturbing, but is there any method in new versions of 3DreamEngine to get an object by mouse click? And getting obstacles betwwen object and camera?

Hmm yesnt, there is the raycast library: https://3dreamengine.github.io/3DreamEngine/docu/extensions/raytrace

local result = raytrace:cast(tavern, origin, direction)
if result then
    coll = result:getMesh().name
end

However it only returns the mesh (and position etc), not the parent objects. And since meshes can be shared this is not unique either.

I think I will need to add the parent object as well...

I think I will need to add the parent object as well...

That'll be good: this thing stops me from updating 3DreamEngine's version in my project.