How I fixed Player's Y transform being shifted at runtime

I observed an oddity with my game. I only noticed it because, when aiming the arrow at what should have been Player’s midsection, it actually connected with his thigh.

At least it wasn’t the knee, though. Arrow in the knee is a HUGE problem.

Anyway, for some reason, at runtime, my Player’s transform.position.y was being set at approximately 0.2. Even though all the prefabs and models and everything were all had Y=0. After poking around with it a little bit, I got the intuition that it might have been the NavMesh. And then I noticed what’s in this picture below. See how the blue overlay of the NavMesh comes up to the Player’s ankles?

After monkeying around for a bit, I found that by ticking ‘Height Mesh’ and re-baking, I could preserve the Player’s Y transform at runtime. Note that this doesn’t change the NavMesh. The blue overlay still passes through the character’s ankles. But Unity no longer moves the character on top of the NavMesh surface. See image below.

2 Likes

Well done!

Privacy & Terms