CharacterMotor, FPSInputController, PlatformInputController in C#

As stated this happens if the whole project does not compile due to compile errors in a file of your project. Unity does not allow attaching scripts before everything is compiled since it needs to run some reflection code on the component to grab the serializable fields, event methods etc.

Works fine, i love you =)

Made my midnight!

Oh my god this was a life saver. Saved me so much time! Thanks for the post :slight_smile:

You rock, I was about to do this myself, thanks a ton!

I tried to use this c# Character Motor script, and it seams to work fine in the Editor.
However, as soon as I publish a Web player version, the gravity and controlling the character is totally different. It seams Iā€™m standing on the Moon, everything is with a low gravity somehow.
However when I go back into the Editor, everything seams to be fine.

Anyone else has had this problem with the C# Character Controller, do I need a new version. If so, where can I find that new version?

Hi JD,

Very hard to assess. I did not use the scripts in the latest versions of Unity, but are not aware of any changes which could lead to the artefacts you describe. Did you check the log for any errors at runtime? Do you see a way to runtime debug the issue in more detail?

xad

There are no errors nor warnings, it just works fine in the Editor without any hassle. As soon I build a web version it seams Iā€™m walking on the moon.
Here is a link to the webplayer. Itā€™s a wip, but just to check it yourself: http://bit.ly/131T9bb ( 30 mb download, can take a while )

Thank you! This should really be included by default with the package in Unity. Appreciate your sharing! Saved me more time than I can imagine.

Sorry for the reply on my own post, but this is for future reference for anyone having the same problem.

I fixed this bug. It seamed that when you have the javascript version of Character Motor script and the C# in the same project. There seams to be an conflict happening on the serialization of publishing your project. No errors or warnings are output to the console, but what happens behind the scene is this.

A script written in javascript and C# with the same name cause a conflict and corrupts the game data. Which means strange things occur when you publish your game. From freezing standalone game, to strange behaviors in the webplayer game experience.

You fix it simply by:

  • Make sure no script is named the same, no matter if one of them is written in a different language. It will cause a conflict. Just remove one of them will fix the serialization conflict.

I hope it helps someone, took me about 2 weeks to find this issue, because the errors written down in the standalone development build arenā€™t referencing any logical explanation. Because it said, your data is corrupted, try remove it. Another error was: object position out of bounds. I had to Google for solutions and found an old topic about this error.

Thanks.

I donā€™t normally respond to any kind of threads, but you seriously saved me a lot of time, and for that I wanted to be sure to say thanks and give some constructive feedback since Iā€™ll be using this as well.

So thank you very much!

I did a quick comparison of all the conversions in BeyondCompare, and it looked like a solid conversion (with a couple value differences). I do have a couple of things to note, however (only pertains to CharacterMotor.cs):

While it was a literal translation of values, Unity (as far as Iā€™ve read) has an odd habit of caching the Inspector values without ever updating the script behind the scenes. That said, I believe that when you first create a CharacterController, it inherently uses different values than what is in the CharacterMotor script (e.g. movement speeds, jump values, slide speed).

You may notice when you first use the C# version, it feels different running and jumping than if you are using a clean CharacterController with the native javascript code behind. The values are the same in both files, but something is still off. I believe this is the caching issue I read about, as you can see that the values in the Inspector are different than what is in the javascript for a clean controller.

This is easily remedied, however, by just copying down the native values from the inspector to the C# CharacterMotor file.

You must explicitly label the canControl and useFixedUpdate variables at the top of the C# CharacterMotor file as ā€œpublicā€ if you want to be able to see them in the Inspector, like you can with the javascript file.

Hope that helps someone else out there. And seriously, thanks again, xadhoom. I really appreciate not having to reinvent the wheel.

I must say, this saved my day. I was about 40 lines into converting that looooooooong CharacterMotor script to C# myself when i decided to have a look and see if anyone else had already done this. Found one or two, but all of them were modified in some form or another. Couldnt find an EXACT conversion of functionality so i just went back to doing it myself. Took a break, came back, decided to look a little more and thankfully found this thread. Probably wouldve taken me a good bit into the morning to convert the code myself, so i feel obligated to say thank you for this wonderful post.

Thank you so much!!

Xad,
You are a great human being.

You will be my first time commenting on these forums.

Four years later and this is still useful. I was just about to upgrade all of the java files to C#for ease of use on my end, I am very glad that I assumed I wasnā€™t the first to think to do so.

I got about 30 lines into doing this while updating a project and decided to do a search instead. Just wanted to say thanks for saving me some time.

Guys :frowning: I made exe and tested it on two computers and with this code when I make any step ( left/back/forward) everything turning black and application not responding ( but in editor works well ) and js version works well.

Hey,

Iā€™m having the same problem, but with Android.

When I move the player in android, its position changes to NaN.
It works in the editor and through the Unity Remote tool.

Anyone had any luck fixing that?

Thanks,
Drew

This really helps! Thanks alot! Truly enough before anyone wastes time converting.

Definitely crediting you for the conversion. :slight_smile:

Iā€™ll post for any problems encountered on the script conversion.