Search Unity

CharacterMotor in C# makes character disappear - only on iOS devices

Discussion in 'iOS and tvOS' started by shaneneville, May 12, 2011.

  1. shaneneville

    shaneneville

    Joined:
    Jan 8, 2011
    Posts:
    7
    I've been tracking down a very strange bug and was hoping someone in the community has come across it before.

    I'm using the C# version of the CharacterMotor and PlatformInputController from Standard Assets (full script available here: http://forum.unity3d.com/threads/64378-CharacterMotor-FPSInputController-PlatformInputController-in-C and everything works fine in the Unity IDE, web build and Mac build, but when I build and deploy to device, my character either never appears or is instantly destroyed.

    I've narrowed it down to these two lines in CharacterMotor.cs:

    Code (csharp):
    1. movement.collisionFlags = controller.Move(currentMovementOffset);
    2.  
    3. tr.position += pushDownOffset * Vector3.up;
    When I comment them out, the character doesn't move, but at least he appears.

    The interesting part is that when I use the UnityScript (JavaScript) version of this same script, with the same equations, the game runs fine on iOS.

    Does anyone know:
    a) If there is something in CharacterController that has problems with C# but not UnityScript?
    b) Why it would work fine on web/IDE and not work on iOS?

    Thanks in advance!
     
  2. shaneneville

    shaneneville

    Joined:
    Jan 8, 2011
    Posts:
    7
    I have continued to track down the issue and the cause appears to be Vector3.Project and probably related to type casting.

    Here is the original line in the C# script which has an undefined variable in projectedMoveDir:

    Code (csharp):
    1. var projectedMoveDir = Vector3.Project(inputMoveDirection, desiredVelocity);
    Here is the syntax corrected line:

    Code (csharp):
    1. Vector3 projectedMoveDir = Vector3.Project(inputMoveDirection, desiredVelocity);
    The problem still occurs with the variable defined as a Vector 3. I'm quite new to C# and vector math and I'm wondering if I'm using the correct syntax for Vector3 and Vector3.Project in this instance?

    Any help is greatly appreciated.