- Home /
How can I have a CharacterController's height make it to where the feet are correctly on the ground?
Basically, I want the script to have the bottom of the collider be where the feet are. This is what I tried, but it is glitching. (Just the function)
     void moverPosition()
     {
         Vector3 moverPos = mover.center;
         float footAverageX = (leftFoot.position.x + rightFoot.position.x)/2;
         float footAverageY = (leftFoot.position.y + rightFoot.position.y) / 2;
         float footAverageZ = (leftFoot.position.z + rightFoot.position.z) / 2;
         Vector3 footAverage = new Vector3(footAverageX,footAverageY,footAverageZ);
         float ySet = footAverage.y + playerHeight;
         moverPos.y = ySet;
         mover.center = moverPos;
         Debug.Log(ySet);
     }
I think it might be a good idea to post some more of your code; that way we get a better idea of what you're trying to do, and where it might be going wrong. Even if you re-post the above code with some commenting thrown in, we'll have a better understanding.
- What is "mover" (I'm assu$$anonymous$$g it's your collider)? 
- How is "playerHeight" calculated? 
 
As an initial guess, it looks as though you might be calculating "ySet" incorrectly, as you're adding the average foot position in the Y-axis to the player height, which would give you the Y-position of the top of your character's head. I think you need to change the line to;
 float ySet = footAverage.y + (playerHeight / 2);
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                