1
\$\begingroup\$

I was using Unity's Character Controller component, but I found it very limited and wanted to tweak some things.

I thought about creating my own character controller from scratch, but it would be much easier if I could start with Unity's Character Controller script and just tweak what I need.

How can do that?

\$\endgroup\$
5
  • \$\begingroup\$ You could always open the source of the CharacterController or just extend the existing one. \$\endgroup\$
    – Zibelas
    Jan 17, 2022 at 19:09
  • \$\begingroup\$ How do I open the source? \$\endgroup\$ Jan 17, 2022 at 19:13
  • 1
    \$\begingroup\$ For me it is in Rider double left shift and the name. forum.unity.com/threads/character-controller-source-code.532107 there they claim it is just a wrapper for the PhysX Controller \$\endgroup\$
    – Zibelas
    Jan 17, 2022 at 19:21
  • \$\begingroup\$ @Zibelas I think this would be worth sharing as an answer. \$\endgroup\$
    – DMGregory
    Jan 17, 2022 at 20:15
  • \$\begingroup\$ Yes. If @Zibelas writes the answer I can mark as the correct answer. \$\endgroup\$ Jan 17, 2022 at 23:30

1 Answer 1

3
\$\begingroup\$

The shipped CharacterController is located in the UnityEngine.PhysicsModule.dll. Now depending on the IDE you are using, you could still take a look at the source. For Rider the shortcut to search for everywhere is double left shift. Entering CharacterController and opening the file is decompiling as good as it can for a readable format. That does not mean you can make changes to the file and expect it to work.

But after taking a look at the soure, you will notice that there is no actual logic in the Controller. A quick google brought this one up: Source for CharacterController where the post claims, that Unity is just using the PhysX from the physics engine and wrote a wrapper for it.

You could now write a wrapper for the wrapper and just cherry pick the functionality you want or go right away with your own CharacterController. If you want to take a look at the full source of it, it should be available here: NVIDIAGameWorks PhysX

\$\endgroup\$
3
  • \$\begingroup\$ Thanks. I wanted to create special cases that would prevent the isGrounded bool to be true. I'll change my approach then. \$\endgroup\$ Jan 19, 2022 at 14:06
  • 1
    \$\begingroup\$ The character controller offers a quick and easy way to test your game. It has a lot of drawbacks as well for that it doesn’t respond nor uses physics in any way. Depending on your game, you might be faster writing your own fully instead. \$\endgroup\$
    – Zibelas
    Jan 19, 2022 at 14:55
  • \$\begingroup\$ That's what I ended up doing. Thanks for the help \$\endgroup\$ Feb 6, 2022 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .