Setting the center of a collider doesn't work.

I have written this function:

void UpdateGroundCheckPos()
{, 0.0f, -body.height / 2.0f);

Where “groundCheck” is a BoxCollider (set to be a trigger) and “body” is a CapsuleCollider.
What this line should do is teleport the “groundCheck” collider below the “body” CapsuleCollider, but when it executes I can see the center property of the ground check not changing.

I also tried calling it every frame but it still doesn’t do anything to the center of the ground check.

[151111-inkedcapture-li.jpg |151111]


As you can see in the first picture the height is 2 and centerY is -1 and in the second picture the height changes to 1 but centerY remains -1, even though it should be -0.5.

You aren’t changing the center of the Collider you are changing the center of the Bounds of that Collider. Try it like this instead:, 0.0f, -body.height / 2.0f);

Bunny83 is right. The line I wrote above isn’t correct. = new Vector3(0,0,-body.height / 2f);

Will do the trick

This doesn’t work. Like AlraNox said, first of all you try to change the bounds of the collider (which you actually can not change). Second the more important thing is you never actually change anything because “center” is a property of a Vector3 value.

So this line, 0.0f, -body.height / 2.0f);

as well as this line:, 0.0f, -body.height / 2.0f);

Do never invoke the setter of the property because you never assign a value to it. You only read the value. Since Vector3 is a value type you get a copy of the value. You then call Set on the Vector3 value and change the values of that copy in memory. However this has absolutely no effect on the actual collider. You have to do = new Vector3(0.0f, 0.0f, -body.height * 0.5f);

or if you prefer: = Vector3.forward * -body.height * 0.5f;

Here we actually invoke the setter of the center property since we assign a Vector3 value to it.