Shooting a target behind an obstacle. Using a Raycast to ensure a clear shot.
When using a ranged weapon, it's not enough to just approach the target up to the weapon range, but also to ensure that you have a clear shot.
To ensure a clear shot, I use a Raycast from the weapon to the target and continue approaching until a clear shot is possible.
Used colors:
yellow ray - clear shot is possible
blue ray - there is an obstacle
red ray - no obstacle and not target (happens if you try to shoot out of range, not possible with the current logic)
Current game progress playable as WebGl game at:
https://undeadswarm.com
#unitytutorial #gamedev #unity3d