I have a simple player controller with raycast pointing forward. When I hold a button the player will rotate to face the nearest object to the player, but instead I want it to face the nearest object to the raycast.
Is it possible to identify the closest object on either side of a raycast?
In general no. A raycast has no concept for any other objects around it. It only concerns itself with the objects in it’s path and discards all others.
However: As already pointed out in the comments, you could manually search through a list of object if the list of objects is known beforehand.
Other then that there are so called Spherecasts
. Documentation here. These will give you all hit results in a certain radius around the middle line. You can then sort them by distance and/or calculate the distance from the center line yourself. This is the closest i can think of that might do what you are searching for.
Let me know if that helped.