Author Topic: (HGS) How to determine if tiles are culled  (Read 151 times)

unaligned

  • Newbie
  • *
  • Posts: 11
    • View Profile
(HGS) How to determine if tiles are culled
« on: December 01, 2019, 07:54:11 AM »
Is there any programmatic way to determine if tiles are culled when you select the 'Cull Back Tiles' option? I'm using a TextMesh to display text on each individual tile, and I don't want to show that if the tiles are in the back. Trying to figure out how.

Thanks.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5390
    • View Profile
Re: (HGS) How to determine if tiles are culled
« Reply #1 on: December 01, 2019, 08:44:36 AM »
Hi,

You could use the dot product between the direction from camera to center and the normal of the tile.

View direction vector:
Code
Vector3 viewDir = (hexa.transform.position - Camera.main.transform.position).normalized;

The normal of the tile can be computed using:
Code
Vector3 tileNormal = (hexa.GetTileCenter(tileIndex) - hexa.transform.position).normalized;

Now, if the dot product between viewDir and tileNormal is >0, it means the normal is in the facing away from the camera hence it's on the back of the sphere.

unaligned

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: (HGS) How to determine if tiles are culled
« Reply #2 on: December 01, 2019, 01:01:06 PM »
Hi,

You could use the dot product between the direction from camera to center and the normal of the tile.

View direction vector:
Code
Vector3 viewDir = (hexa.transform.position - Camera.main.transform.position).normalized;

The normal of the tile can be computed using:
Code
Vector3 tileNormal = (hexa.GetTileCenter(tileIndex) - hexa.transform.position).normalized;

Now, if the dot product between viewDir and tileNormal is >0, it means the normal is in the facing away from the camera hence it's on the back of the sphere.

This was very helpful. I had to change it to > ~ -.13 because it was still showing when it was behind, but this got me there. Many thanks!