CharacterMotor, FPSInputController, PlatformInputController in C#

Hi,

Since we are programming mainly with C# I had to convert some of the js character scripts shipped with Unity to C#. Before anybody else wastes his time for this here they are.

If you encounter any problems/inconsistency using these compared with the js version please let me know.

xad

411276–14249–$CharacterMotor.cs (25.6 KB)
411276–14250–$FPSInputController.cs (1.76 KB)
411276–14251–$PlatformInputController.cs (3.06 KB)

17 Likes

Thanks for these.

I’m still using my C# version of Eric5h5’s upgraded first person controller, but that was mainly because CharacterMotor etc. was JS. :slight_smile:

I’ll check these out when I get home.

I am bumping this because this is great. Saved me a lot of trouble!

Thank you, thank you and thank you again
I was starting struggling with the Javascript version and interacting with c#…

I’ve been having problems with the C# CharacterMotor script that only appear on iOS (it works fine in the IDE, webplayer and Mac builds)

The following line causes my character to disappear when the game is running on iOS:

var projectedMoveDir = Vector3.Project(inputMoveDirection, desiredVelocity

I changed the variable definition, but it still creates the same problem.

Vector3 projectedMoveDir = Vector3.Project(inputMoveDirection, desiredVelocity);

There are also a couple of other places in the CharacterMotor where var is used instead of float.

If anyone has a fix for the Vector3.Project issue, any help would be greatly appreciated!

Thanks for going through the pain of doing this and sharing it :wink:

Have you found the solution of your problem? I am in the same situation… what version of unity are you unsing and on what IOS?

i’m on unity 3.4 with IOS 5

Honestly? I just commented out the line and carried on. Vector3.Project seems to have some problems on iOS and since my game didn’t use ‘TooSteep()’, I just took it out.

I spent about 2 hours converting the CharacterMotor only to have it not work as expected. Thank you. Now I don’t need to reinvent and find the structural problems with the wheel.

Long time ago… you are welcome :wink:

Thank you! Saved me some time :slight_smile:

a hey guys I got problem with this code…
here is what I am getting:


that happens every time I connect to my photon server with client and join a random team in result a player is spawned with this script…
anywho could help me?

Hard to answer …
The controller is NULL or “this” is NULL …
Hard to answer without more context.


That is all I can give, I basicly dont get what is wrong with it, there is both controller and the gameobject exists…
what now :frowning:

Hi,

This looks a bit odd. Did you debug the code at this line (before the exception is thrown). What part of the equation leads to the issue? It looks very much as if the controller is null…

Maybe the order of script initialization is a problem here.

xad

defaq, I added debug.log and it says its null…now what :frowning:
its paradox, I looked on player prefab both playing and in editor and both cases I saw the Character Controller,
yet the dumb script dosent see it >:( oh and about the script init…
script is lockated in “Assets/Scripts/”.
and also the Execution Order is default.
please guys help :frowning: I am totaly lost :frowning:

Did you check that the controller has been set before the call? Btw. I recommend to use Monodevelop debugging for easy stepping through the code here. log messages might be a bit limited here.

I see that the FixedUpdate() method leeds to the call of the method. At least at this point the Awake() and Start() methods should have been called…

well it does
controller = this.controller inside of awake function…
that is the only place where it is decleared…
maybe some other method is required? if so please do write down witch :slight_smile:

oh damn, I found the problem, :smile:
now its solved :smile:
sadly Collage starts today :frowning:

I’m hoping that these will work without much modification but serious thanks for this! I was trying to do the same sort of conversion and i thought i’d search first. Glad I did!

Thanks !

EDIT:
Ok, This is great but when I try to add these scripts to my PlayerController I get and error saying “Can not add scrip. Script needs to finish compiling before adding it” or some such.

Any ideas why this would happen?