Changing the shape of my player during the game

I’m very new to Unity and I have been following a tutorial series on making a speed running type game.

One idea I had to develop the game further is to allow my player, which is currently a cube to flatten so it can slide under obstacles.

I’m quite lost, how would I go about doing this?

Any comments/advice would be appreciated.

Kind regards,

Rob

The Transform of the game object / cube has a scale property. Assuming that the local y axis (green axis) of the cube is running up/down along with the world y axis. You can scale the cube down to the size you need on that axis by doing the following:

float desiredYScale = 0.5f;
void Start(){
    desiredYScale = transform.localScale.y * desiredYScale;
}

void Update(){

    transform.localScale = new Vector3(transform.localScale.x, desiredYScale, transform.localScale.z );
}

That will scale the object by half of its current size, but it will pop to this scale, if you want a smooth transition, you can use lerp for example.