Player controller y axis issue

Hi everyone,

first of all, please forgive me if I am using any wrong terminology/jargon. I am moving from web dev to game dev and am on my 3rd day of learning.

I wanted to get an answer on an issue I have had with player controller.

I added a player controller to my character and used the script on the page

I understood the code and it worked fine. mostly.

However, I realized that each time I pressed play, my character would suddenly move to a different y position than the one I put. Eventually I came to realize that he was moving in relation to the value within the player controller Y axis.

So, with Transform>y axis set to 0 and Player controller>y axis set to 0 as soon as i hit play, the character’s transform>y axis jumps to 2 (which makes the character float above the ground) but the player controller>y axis stayed at 0.

However, changing the player controller>y axis to 1.1 and keeping the transform>y axis at 0 fixed the issue and kept the transform>y axis at 0 when hitting play.

Although I have overcome this issue, I don’t understand it and would be grateful for someone to help me figure out this behavior.

Many thanks in advance to all who reply.

From your description I think it may be related to a collider issue.

Character Controller uses Capsule Collider that has height and radius parameter. The height describes ‘how tall’ is your character.

It might be that your Transform.position.y when set to 0 in Inspector makes a part of your capsule collider go underneath the collider you have on the ground level.

That’s probably why it changes on the Play mode. When you hit Play, Unity physics starts to work. Collider detects it’s inside another collider and because your character isn’t static - it has Character Controller (which is basically a kind of rigidbody) - it pushes it up so the bottom of the capsule collider is touching the top of your ground collider.

1 Like

Thank you Mathew :slight_smile:

I thought this might be the case as when i first add the character controller the capsule is half under the ground. I moved this up and thought everything else would revolve around its new settings.

would you be able to advise on what is best practice going forward? or is there nothing wrong with the way I’ve resolved this?

thanks,