Getting a raycast hit point

@agallegos
I came across this post when searching about Raycasting in Cesium.
What is the best way to get a raycast hit point, because using ScreenToWorldPoint will always return 0, 0, 0 for the origin. I guess this is expected because the camera will always be rebased to the new axes.
Thanks

Hi @sonny_unity,

It sounds like you’re asking about raycasting in Unity instead of Unreal, so I’ve moved your post to a new topic in the Cesium for Unity category.

I’m looking into your query and I’ll let you know what I find out!

-Alex

Hi @sonny_unity,

I would recommend using Physics.Raycast rather than ScreenToWorldPoint. For something similar, you could implement it along the lines of

RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward), out hit, 100000.0f))
{
}

The hit position can be retrieved with hit.transform.

Hi @agallegos ,
thanks for the follow up. In my case, say I have an object at longitude, latitude, elevation.
After converting to Unity coordinates and raycasting from this object to the terrain, I found that it didn’t return the height of the terrain itself, but a much larger value. Actually I’m not sure what the raycast hit as it just went through the CesiumWorldTerrain.
My expected hit.transform will be a point on the terrain, and the distance will be equal to elevation.
On the Cesium3DTileset script I have the “Create physics meshes” option enabled.