Hello,
I would either:
- Change the size of the hat
- Add a masking function to the hat’s material that will hide all hair in contact with it
or - Create multiple versions of the same hairstyle, where you shave off any parts that are occluded beyond the hat line so they don’t stick out.
There’s a reason characters are usually buzzcut/bald when wearing hats in video games.