I think this has to do the steps being to far appart so you need to make a feature where it steps back when inside a tree or make the character move one pixel at a time at a very high speed (which i assume it has already been done)
it can glitch when you have bad internet. I play on very fast internet and never get stuck in trees. either that or you hold shift for too long and you brush by some trees.