Search Unity

Motor Torque faster on smaller devices

Discussion in 'Scripting' started by Cjmarkham, Jul 23, 2014.

  1. Cjmarkham

    Cjmarkham

    Joined:
    May 30, 2014
    Posts:
    41
    I am using the following method to apply torque to a wheel:

    Code (CSharp):
    1. if(joystick.tapCount>0){
    2.     backRight.motorTorque =25000*1.0f*Time.deltaTime;
    3. }
    This is called in the Update() method.

    This works fine on my 1920x1200 tablet and also on a friends 1920x1080 tablet. However on another friends 800x480 phone the car moves far too fast. The same happens on his friends 1280x800 tablet.

    Anyone know why the resolution could be affecting this?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Spider-sense tells me the problem is just outside the lines of code we see here. Can we get a little more context?
     
  3. Cjmarkham

    Cjmarkham

    Joined:
    May 30, 2014
    Posts:
    41
    Sure thing. I think this is all of the relevant code.

    Code (CSharp):
    1. private Joystick joySteer;
    2. private Joystick joyGas;
    3. private Joystick joyBrake;
    4.  
    5. void Update () {
    6.     int brakeAxis = joyBrake.tapCount;
    7.     if (brakeAxis != 0) {
    8.  
    9.         if (speed > 0.01f || speed < -0.01f) {
    10.             DesiredRPM = IdleRPM;
    11.            
    12.             backRight.motorTorque = 0.0f;        
    13.             backLeft.motorTorque = 0.0f;                
    14.             frontLeft.motorTorque = 0.0f;
    15.            
    16.             backRight.brakeTorque = 0.5f;
    17.             backLeft.brakeTorque = 0.5f;
    18.             frontLeft.brakeTorque = 0.5f;
    19.         } else {
    20.             backRight.motorTorque = 25000 * -1.0f * Time.deltaTime;        
    21.             backLeft.motorTorque = 25000 * -1.0f * Time.deltaTime;                
    22.             frontLeft.motorTorque = 25000 * -1.0f * Time.deltaTime;
    23.            
    24.             backRight.brakeTorque = 0.0f;
    25.             backLeft.brakeTorque = 0.0f;
    26.             frontLeft.brakeTorque = 0.0f;
    27.         }
    28.  
    29.     } else {
    30.  
    31.         backRight.brakeTorque = 0.0f;
    32.         backLeft.brakeTorque = 0.0f;
    33.         frontLeft.brakeTorque = 0.0f;
    34.  
    35.         float gasAxis = joyGas.tapCount;
    36.         if (gasAxis > 0) {
    37.  
    38.             backRight.motorTorque = 25000 * 1.0f * Time.deltaTime;        
    39.             backLeft.motorTorque = 25000 * 1.0f * Time.deltaTime;                
    40.             frontLeft.motorTorque = 25000 * 1.0f * Time.deltaTime;
    41.  
    42.         } else {
    43.             backRight.motorTorque = 0.0f;        
    44.             backLeft.motorTorque = 0.0f;                
    45.             frontLeft.motorTorque = 0.0f;
    46.         }
    47.     }
    48. }
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    spider senses tell me you should apply physics in FixedUpdate rather than Update.

    x