Help! I need to make a directional light constantly point at an object ,How to make a directional light always point at an object.

I’m creating a game in which the player’s health goes down when not in the shade. I’ve created a script that shoots a ray cast from the player to the directional light and that seems to work.

The problem I’m having is with is the day/night system. I currently have the directional light orbiting the level using a free asset from the store. However, orbiting the level does not change the shadows so the player isn’t losing health(because the directional light is below the ground) but isn’t visible in the shade. One possible solution I can think of (which I’m not sure will actually work) is to place an object underground and have the directional light constantly point at it as it orbits.

When looking for the answer in other posts most say just rotate the directional light and leave it stationary, however that wouldn’t work in my case because a raycast is shot from the player to the sun. I’m fairly new to game development and coding in general so if anyone knows of any easier way any help would be greatly appreciated. ,I’m creating a game in which the player’s health goes down when not in the shade. I’ve created a script that shoots a ray cast from the player to the directional light and that seems to work.

The problem I’m having is with is the day/night system. I currently have the directional light orbiting the level using a free asset from the store. However, orbiting the level does not change the shadows so the player isn’t losing health(because the directional light is below the ground) but isn’t visible in the shade. One possible solution I can think of (which I’m not sure will actually work) is to place an object underground and have the directional light constantly point at it as it orbits.

When looking for the answer in other posts most say just rotate the directional light and leave it stationary, however that wouldn’t work in my case because a raycast is shot from the player to the sun. I’m fairly new to game development and coding in general so if anyone knows of any easier way any help would be greatly appreciated.

I’m not sure if I completely understand (perhaps a screenshot of your game would explain things) but…

What I’d do is create a sort of “rig” by having a GameObject (representing the rig) with your directional light (acting as the sun) as a child object. Position your sun relative to the rig as required and rotate it so that it points towards it. By rotating the rig, you will then automatically cause your sun to orbit and rotate at the same time as required.