Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raycast method cast params #64

Open
CrossroadInTheVoid opened this issue Jun 19, 2023 · 3 comments
Open

Raycast method cast params #64

CrossroadInTheVoid opened this issue Jun 19, 2023 · 3 comments

Comments

@CrossroadInTheVoid
Copy link

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.

@CrossroadInTheVoid
Copy link
Author

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?

@Luke100000
Copy link
Collaborator

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...

@CrossroadInTheVoid
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants