public virtual WorldRaycastResult Raycast(Ray ray, bool ignoreTerrainNonColliders, float maxDist = float.MaxValue, params Player[] ignorePlayers) { TerrainRaycastResult tResult = RaycastTerrain(ray, ignoreTerrainNonColliders, maxDist); PlayerRaycastResult pResult = RaycastPlayers(ray, maxDist, ignorePlayers); if (tResult.Intersects && (!pResult.Intersects || (pResult.IntersectionDistance.Value > tResult.IntersectionDistance.Value))) { return(new WorldRaycastResult(tResult)); } else if (pResult.Intersects && pResult.Player.Health > 0) { return(new WorldRaycastResult(pResult)); } else { return(new WorldRaycastResult(ray)); } }
public PlayerRaycastResult RaycastPlayer(Vector3 origin, Player player, float maxDist = 2000f) { Vector3 dir = (player.Transform.Position - origin).Normalize(); Ray ray = new Ray(origin, dir); TerrainRaycastResult tResult = TerrainPhysics.Raycast(ray, true, maxDist); float?dist; PhysicsBodyComponent playerPhysics = player.GetComponent <PhysicsBodyComponent>(); bool hitPlayer = ray.Intersects(playerPhysics.GetCollider(), out dist); if (hitPlayer && dist.Value <= maxDist && (!tResult.Intersects || dist.Value < tResult.IntersectionDistance.Value)) { return(new PlayerRaycastResult(ray, true, ray.Origin + ray.Direction * dist.Value, dist, player)); } else { return(new PlayerRaycastResult(ray)); } }
public WorldRaycastResult(TerrainRaycastResult result) : base(result) { TerrainResult = result; }