Follow-up to "Grenade can be thrown through a wall"

Many thanks to bixarrio for his code in the original post…it helped me greatly.
I did have to add/modify a few items to match my script (GrenadeAction.cs) so I thought I would pass along my solution.

First, I added : [SerializeField] private LayerMask obstaclesLayerMask;

This needed to be added in able to look to the Obstacle Layer.

Second, I needed to twik the last line of bixarrio’s code to match mine: return Physics.Raycast(ray, distanceToTarget, obstaclesLayerMask)

Third, I added his if (ObstacleInTheWay(unitGridPosition, testGridPosition)) continue; just before the line validGridPositionList.Add(testGridPosition);

Last, I updated the doors to reflect the Obstacle Layer (so the player cannot throw through the doors).

This works for me. Hope it helps others.
Thanks again to bixarrio for his original code.

5 Likes

Link to the original post for anyone that’s interested

3 Likes

Privacy & Terms