dello32
9 months agoMember
RaycastGizmo with objectTag
I'm trying to use RayCastGizmo with objectTag, but it seems like the tag set in the interface isn't being used in the script.
Example:
const options = {
layerType: hz.LayerType.Objects,
maxDistance: 10
};
const hit = this.rayCaster!.raycast(origin, direction);
Will hits all objects, not just the ones with the objectTag set in the RayCastGizmo.
Has anyone else run into this? Has this feature been removed
- I'm coming back to try and wrap up this discussion.
- The original question:
Does the "objectTag" option set in the RayCastGizmo interface get used in the script?ANSWER: no, it's not taken into account.- My apologies:
Gausroth actually pointed me in the right direction from the start. I just didn’t understand how to access hit.target (my IDE didn’t show it — I just needed to cast hit properly to EntityRaycastHit).- Conclusion:
Here's a small function that might help clarify things and be useful to others.export function rayCastObjectByTag(rayCaster: hz.RaycastGizmo, direction: hz.Vec3, tag: string, maxDist = 10): hz.RaycastHit | null {const pOrigin = rayCaster.position.get();const options = { layerType: hz.LayerType.Both, maxDistance: maxDist };const hit = rayCaster.raycast(pOrigin, direction, options);if (hit && hit.targetType === hz.RaycastTargetType.Entity) {const entity = hit.target;if (entity.tags.contains(tag)) return hit;}return null;}Thanks a lot for your patience 😉