Scale / rotate ANY type of collider with transform?

How would I scale and rotate any type of collider in 3D with the current scale and rotation of the transform the collider is currently attached to WHILE playing the game? This makes it useful for when I need to do a slide under a wall in my game.

It can use either bounds size / rotation or anything else related to that as well.

Thank you & have a VERY Merry Christmas! <3

Don’t they already do that?

RadRedPanda Not when your character changes scale / rotation while playing, they simply follow the player. They don’t change at all.

Can you show me a picture? I don’t think I quite understand what you mean. Mesh Colliders already match the transform’s changes that they’re on during Play mode, so you must mean something else from what I’m imagining.

CharacterController always acts as an upright capsule. Capsule and other simple colliders also do not react to non-even scaling, as they’re optimized for the simplest possible math instead of general-purpose matrix math.

But you can change the general parameters they offer (radius, bounds, etc.) at runtime, just like any other component public parameters.

Or you could have a different set of colliders which are more appropriate for when your character is in an odd situation like sliding under a wall, and enable/disable them as required.

halley I’m using a Rigidbody.

RadRedPanda I want to rotate AS WELL AS scale a 3D capsule collider with the current scale / rotation of my player at runtime.

You can only adjust radius and height for a capsule. That’s what I’m saying. You cannot adjust the transform independently, as that requires a lot heavier math for the physics system. I have seen similar games just set the radius really large and the height really short, for an approximation of the graphical character parts when they’re prone.

Like I said, Colliders already try to match their object’s transform values. The simple colliders won’t fit perfectly with scale, but will still rotate to match your object. If you want it to match the player perfectly, you’re going to want to use a Mesh Collider and put in a Mesh of a Capsule, as the simple colliders use very minimal calculations to create their shapes.

I just did this and it’s still not scaling / rotating to the current scale / rotation of player.

I don’t know why but I can’t get the shape of the mesh collider to be the shape of my character.

How would I get the Mesh Collider to be the shape of my character?

@AnimalManUK : I did that. It’s Convex and has a rigidbody, but it’s still not taking the shape.

Here is a screenshot of what SHOULD be happening. “JammoPrefab” has the Mesh Collider but as you can see, it is not shown in the Mesh Collider Shape list.

candiddelectableasiaticmouflon

@AnimalManUK : That’s what I’m saying… JammoPrefab is not showing up in the list. I clicked the bottom right button… It’s not letting me select “JammoPrefab”.

Because prefabs aren’t meshes?

1 Like

@spiney199 Well this is and it’s still not showing up in the menu

Imported models are in essence, prefabs, with multiple meshes assets as sub objects. If your model is made of many multiple smaller mesh objects… have fun with that.

A better question is why you want to be scaling and rotating a complex collider (answer, you don’t). You should just use a capsule collider and change the height and radius as needed in your code.

1 Like

how can I do that in code? I’d rather use a capsule collider honestly, but when sliding, my player can’t fit through the wall.

Just modify the height properties of the capsule collider: https://docs.unity3d.com/ScriptReference/CapsuleCollider.html

1 Like
Error CS0246 The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)