I am trying to make a strategy kind-of game and I need to know on what entity is my mouse hoovering so i can select them. To do that I thought to use the code that is on raycast from top down shooter sample. For now I dont care that the bullet that is used as UI to show where the mouse is is on the ray-hit point. I will make that UI part later as 2d.
My problem is that I am not sure how to get the entity that I the ray is colliding.
Do i need to use On collision events and check where the ray is colliding or i can do it elsewhere.
Re: Get/find entity that colides with raycast hit point
#2To modify the example in the topdown template:
Code: Select all
const auto rayFlags = rwi_stop_at_pierceable | rwi_colltype_any;
ray_hit hit;
IEntity* pHitEntity = nullptr;
const bool bRayHit = gEnv->pPhysicalWorld->RayWorldIntersection(vPos0, vDir * gEnv->p3DEngine->GetMaxViewDistance(), ent_all, rayFlags, &hit, 1);
if (bRayHit && hit.pCollider != nullptr)
{
pHitEntity = static_cast<IEntity*>(hit.pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY));
if (pHitEntity != nullptr)
{
//..
}
}
Re: Get/find entity that colides with raycast hit point
#3Thanks that worked really well.To modify the example in the topdown template:
Code: Select all
const auto rayFlags = rwi_stop_at_pierceable | rwi_colltype_any;
ray_hit hit;
IEntity* pHitEntity = nullptr;
const bool bRayHit = gEnv->pPhysicalWorld->RayWorldIntersection(vPos0, vDir * gEnv->p3DEngine->GetMaxViewDistance(), ent_all, rayFlags, &hit, 1);
if (bRayHit && hit.pCollider != nullptr)
{
pHitEntity = static_cast<IEntity*>(hit.pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY));
if (pHitEntity != nullptr)
{
//..
}
}