Physics raycast with unity scales

Hello everyone,

I have recently picked up game development again as a hobby and am a bit confused when it comes to the scales in Unity. I am trying to make a script that checks if the player is grounded. I want the player to be 2 meters tall. I use a scale of 2 on the Y axis for this. See the image called playerScript.png .
in the inspector i have set the playerheight to 2 aswell to make it the same. I use the code below for my check.

 void Update()
    {
        //ground check
        Debug.DrawRay(transform.position, Vector3.down * (playerHeight * 0.5f + 0.2f), Color.red);
        grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, onTheGround);

        MyInput();

        Debug.Log(grounded);
        if (grounded)
        {
            rb.drag = groundDrag;
        }
        else
        {
            rb.drag = 0;
        }
    }

The result of the raycast remains false. The red line from the debug seems to only go about 0.5m as you can see in image called redline.png .

Is there something i am confusing about the Y axis? Or how does unity work with these scales?

Thank you in advance!

Kind regards,

Alex


9438440--1323845--redline.png

The default capsule is already two meters tall and so there’s no need to change the scale. Place a default cube (1 meter) next to it to verify.

Oh really? I didnt know that. Now that explains a lot. Thanks!

Are you interested in learning how to make a character controller or do you just need one that works?

Here is a super-basic starter prototype FPS based on Character Controller (BasicFPCC):

That one has run, walk, jump, slide, crouch… good stuff.

BTW - the scale of an object’s transform is just a multiplier and doesn’t actually represent the size of an object. An object could have a transform scale of 1,1,1 and yet be 100 meters tall. It all depends on the scale of the mesh when imported.

To get the actual world height of the object you can do this:

float height=GetComponent<Renderer>().bounds.size.y;

I am learning to make a basic fps character yes. For now i am only making 1 that can do basics like walking, jumping and sprinting.I will have a look at it as i love reading up on new things.

Thank you! I didnt know that. Good to keep in mind for the future