Turret place in a wall

Hey guys. I am trying to do a function that lets the player place a turret on floors.
I was using linetrace so that it could find the location of where the turret can be placed.
When the turret goes near a wall, or on the floor, it goes a little bit inside it, the model gets inside the wall/floor.

Here is a video that shows what I’m talking about:

How do I fix this? Thanks!

There’s a few ways you could fix this:

  • Use a sphere trace instead and use the hit location so the turret placement can never be closer than the sphere’s radius.

  • Change the rotation of the turret to orient itself to the surface of the wall or floor by using the trace’s Hit Normal.

  • Also using the Hit Normal, you can offset the turret away from the trace hit location by a certain number of units, and it can be more or less in Z than in X with Y to fit the non-spherical dimensions of the turret.

There’s probably better ways than one of those three but let me know if one of them solves your problem.

Thanks a lot I will try them soon.