Collision Point with no rigidbody

Hey guys, sounds crazy - but I’m not using a rigidbody to collide with an object in my scene. I actually am unable to use a rigidbody…

Why I am unable to use a rigidbody:
Long story. Essentially, I have a barricade that I set up under the player (iskinematic == true). Previously I turned iskinematic on/off but it doesn’t work because after I move from the location so I am no longer on the barricade, I set isKinematic to false so the player can no longer walk into that barricade… But if you stand next to it and place another, iskinematic is set to true and you can walk through any barricade you’re standing next to.

The actual implementation:
I use Physics.OverlapBox in place of a collider. I have a list of the players standing in the location the barricade is instantiated and they are removed when OverlapBox no longer detects them. When a player runs into the overlapbox, what I want to do is stop my navmeshagent from moving and then set the position so that it is flush with the barricade.

I’ve gotten super close to doing this by using Collider.ClosestPointOnBounds(hit.point), but it’s inaccurate the way that I calculate the hitpoint.

What I need help with:
How do I find the actual collisionPoint? When I run into the barricade and I set the nasvmeshagent inactive, the location it ends up in is inside of the barricade (white cube is my player prefab) slightly: Screenshot - 744378186812eb449f7e3c2f8b09a181 - Gyazo
I need two points for this to properly work: one on the player and one on the barricade collider… But this is seemingly impossible since so many portions of the player contact the barricade.

Many attempts later and sort of spaghetti code working with a stack:
I have this working: Screen capture - 1adee18c56e68c46eca26ab1058b09b7 - Gyazo

Here’s the majority of my code. The ClickToMove portion is pretty straightforward so I didn’t include it:

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Obstruction : MonoBehaviour
{
    private ClickToMove clickToMoveScript;
    private SpawnAndTrackItems spawnAndTrackItemsScript;

    private Collider obstructionCollider;
    private Collider[] insideBox;
    private Vector3 colliderHalfExtents;
    private float colliderWidthAndLength;
    private float colliderHeight;

    private List<GameObject> playersInObstructionAtStart;
    private List<GameObject> playersInBox;
    private List<GameObject> playersToRemove;

    void Start()
    {
        playersInObstructionAtStart = new List<GameObject>();
        playersToRemove = new List<GameObject>();
        spawnAndTrackItemsScript = FindObjectOfType<SpawnAndTrackItems>();
        clickToMoveScript = FindObjectOfType<ClickToMove>();
        playersInBox = new List<GameObject>();


        obstructionCollider = gameObject.GetComponent<Collider>();
        colliderWidthAndLength = obstructionCollider.bounds.size.x;
        colliderHeight = obstructionCollider.bounds.size.y;

        colliderHalfExtents = new Vector3(colliderWidthAndLength, colliderHeight, colliderWidthAndLength) / 2;
        Collider[] insideAtStart = Physics.OverlapBox(transform.position, colliderHalfExtents, Quaternion.identity);

        /**
         * For every player that is in the obstruction on instantiation, add them to a List to allow them to walk through the obstruction temporarily.
         * */
        foreach (var collider in insideAtStart)
        {
            //add one collider per player
            if (collider.gameObject.tag.Equals("Player") && !collider.isTrigger)
            {
                playersInObstructionAtStart.Add(collider.gameObject);
            }
        }
    }

    private void Update()
    {
        /**
         * If any player enters the barrier...
         * */
        playersInBox.Clear();
        playersToRemove.Clear();
        insideBox = Physics.OverlapBox(transform.position, colliderHalfExtents, Quaternion.identity);
        foreach (var collider in insideBox)
        {
            if (collider.gameObject.tag.Equals("Player"))
            {
                playersInBox.Add(collider.gameObject);
            }
        }

        /**
         * When a player exits the obstruction, we add them to a list to remove
         * */
        foreach (var player in playersInObstructionAtStart)
        {
            if (!playersInBox.Contains(player))
            {
                playersToRemove.Add(player);
            }
        }

        /**
         * remove the players we gathered in the list from the startlist. Eventually this will reach zero, and no players can walk through
         * */
        foreach (var playerToRemove in playersToRemove)
        {
            playersInObstructionAtStart.Remove(playerToRemove);
        }

        /**
         * For every player inside the box currently, check to see if we allow them to walk inside or if we force them to collide
         * */
        foreach (var player in playersInBox)
        {
            Debug.Log(playersInBox.Count + " count, player is: " + player.GetComponent<Collider>());
            if (playersInObstructionAtStart.Contains(player))
            {
                //allow the player to walk through as they please
                Debug.Log("Can walk through");
            }
            else
            {
                Debug.Log("Can't walk through");
                if (player.GetComponent<Collider>().bounds.Intersects(gameObject.GetComponent<Collider>().bounds))
                {
                    Debug.Log(player + "" + gameObject);
                    do
                    {
                        player.transform.position = clickToMoveScript.storedLocations.Pop();
                    } while (player.GetComponent<Collider>().bounds.Intersects(gameObject.GetComponent<Collider>().bounds));
                   
                    SetFinal(player);
                    player.GetComponent<NavMeshAgent>().enabled = false;
                }
            }
        }

    }

    public void SetFinal(GameObject player)
    {
        Vector3 obstructionPosition = gameObject.transform.position;
        Vector3 playerPosition = player.transform.position;
        if (Mathf.Abs(playerPosition.x - obstructionPosition.x) < Mathf.Abs(playerPosition.z - obstructionPosition.z))
        {
            //set z (longer position)
            if (playerPosition.z - obstructionPosition.z > 0)
            {
                if (playerPosition.x - obstructionPosition.x > 0)
                {
                    playerPosition.z = obstructionPosition.z + 1.01f;
                }
                else
                {
                    playerPosition.z = obstructionPosition.z + 1.01f;
                }
            }

            else
            {
                if (playerPosition.x - obstructionPosition.x > 0)
                {
                    playerPosition.z = obstructionPosition.z - 1.01f;
                }
                else
                {
                    playerPosition.z = obstructionPosition.z - 1.01f;
                }
            }
        }
        else
        {
            //set x (longer position)
            if (playerPosition.z - obstructionPosition.z > 0)
            {
                if (playerPosition.x - obstructionPosition.x > 0)
                {
                    playerPosition.x = obstructionPosition.x + 1.01f;
                }
                else
                {
                    playerPosition.x = obstructionPosition.x - 1.01f;
                }
            }

            else
            {
                if (playerPosition.x - obstructionPosition.x > 0)
                {
                    playerPosition.x = obstructionPosition.x + 1.01f;
                }
                else
                {
                    playerPosition.x = obstructionPosition.x - 1.01f;
                }
            }
        }
        player.transform.position = playerPosition;
    }
}