Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug makes Mouse Sensitivity terrible

Discussion in 'Scripting' started by roger0, Jan 29, 2015.

  1. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    I have a bug in my game that makes the mouse input extremely stiff and sluggish. It does not happen all the time, but when it does, it makes the game unplayable. Its for my game Air Guardians, which is a flight sim. So the players can barley roll or pitch the aircraft. I have no idea where this bug is coming from. It happens only sometimes, which makes it very hard to track down.

    I load up a new scene and the bug happens, then I exit the scene back to the menu and enter another scene, and the bug is gone.

    If anyone might know the problem, please help!
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    I think you're going to have to post some code.

    Are you appropriately accounting for frame rate in your input code?
     
  3. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    I'm not doing anything with frame rate in my script.

    I am using a package called the Airstrike starter kit for making air combat games. Here are the relevant peices of code that deal with mouse control.

    Here is a peice of code that comes from one script called playercontroller.cs in the update funcion. (flight.AxisControl refers to a function in another script called flightsystem.cs)

    Code (CSharp):
    1. flight.AxisControl(new Vector2(Input.GetAxis("Mouse X")   ,Input.GetAxis("Mouse Y")  ));

    and here is the function that playercontroller.cs is trying to get to in another script called flightsystem.cs

    Code (CSharp):
    1.     public void AxisControl(Vector2 axis){
    2.         roll = Mathf.Lerp(roll,Mathf.Clamp(axis.x,-2,2) * SpeedRoll,Time.deltaTime);
    3.         pitch = Mathf.Lerp(pitch,Mathf.Clamp(axis.y,-1,1) * SpeedPitch,Time.deltaTime);
    4.     }
    5.  
    6.    }
    maybe there are some clues here?
     
  4. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    Hmm..a bit difficult to make out but the only possible suspect I can see is Time.deltaTime in
    the Lerp call. Try changing it to a fixed value between 0 and 1..say to 0.5 and see if you
    get a perfectly steady roll and pitch values..if you do get it, then Time.deltaTime is your
    culprit and it needs to be changed to a different logic.
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Yep, Time.deltaTime in a lerp call is almost certainly incorrect, and means that the speed will change based on frame rate, which you don't want.

    Lerp is for "linear interpolation", it sounds like you want MoveTowards instead.
     
  6. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    At the beginning of every level there is a cutscene that plays. Once the cut scene is finished the game instantiates the airplane that the player controls. It looks like the issue occurs when the game runs through the entire cutscene without skipping over it. So there might be an issue with instantiating the airplane using a coroutine instead of a mouse click, which skips the cut scene.
     
  7. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    Ok, I think you'll need to post more code details here to let us figure
    out further.
     
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    First try switching those Lerp calls out for MoveTowards. Those will definitely make your plane's behaviour change as the frame rate fluctuates.
     
  9. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    I tried replacing the lerp with movetowards, but then it prompted me with error messages so I put the lerps back. I dont really want to change it if its not causing the bug. It might be a better idea, but I'm not sure how to make moveTowards easily work...

    I eliminated a buggy camera control that let you orbit around the aircraft. However, the bug still appeared to exist even after I did that. A little while later I rebuilt the game, and the bug seemed to go away. I'm not exactly sure what happened there, but everything seems to work now.
     
  10. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    How will you know if that's the bug if you don't change it?

    What's the error you got? That's something we can help with.
     
  11. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    The bug is fixed. I think it did not have anything to do with the lerp functions.
     
  12. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    So what do you think it was, then? Don't leave us hangin'!

    (It's good form to post the solution if you solve it yourself after asking, as other people might benefit from it in the future.)
     
  13. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    So I think it had something to do with disabling the controls for the aircraft when the camera orbit control was activated (the middle mouse disables the controls and lets you orbit around the aircraft with the camera). I think disabling the controls was causing strange physics to happen, making the airplanes axis controls sluggish. Be careful when temporarily disabling mouse controls for anything that uses physics.
     
  14. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    The two shouldn't be related unless your code is tying them together. The physics system doesn't pay attention to input itself and isn't concerned about what else (aside from colliders and other physics bits) on your objects is turned on or off.

    In any case, glad you got it solved.
     
  15. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    The bug is still there! I just fixed it on my computer somehow. I tested it on 2 other machines and the problem is still there.

    I replaced the lerps with mathf.moveTowards, but it did not solve the problem, it actually made it worse. For some reason on the other machines, the mouse input is very stiff. Unless I instantiate the object with a coroutine, then its fine for about 10 seconds, then the controls lock up.

    I dont understand why the controls are fine on my computer but not on the others.
     
  16. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    I was actually quite surprised that its working with Time.deltaTime.
    Can you try out what I suggested in #4 i.e :

     
  17. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    What were the results? We can't help you if all we know is "it didn't work". Our help can only be as specific as the information you give us.
     
  18. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    I'm sorry, but I'm really not sure how to describe this bug. It's not like anything I've ever seen before. I find a solution to the problem, and then it shows up again without me changing a single thing. It's probably best if I hire an experienced programmer as this beyond my skill.
     
  19. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553

    Or for free you could post more than a few lines of code and I bet penguin could help you here. He's figured out or helped more than once around here.
     
  20. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208

    Apologies, but i'm a bit lost as to what code to exactly show them. I just posted a piece of the script because I did not want to burden anyone with looking through a large script with unrelevant code. And I'm very irritated with this bug. You know how it is to work with a bug that has apparently come from hell.

    Here is some more info

    I have 3 PC computers at home (one for each family member!) The bug used to happen on all machines.

    The only time when it did not happen on all machines was when the player skipped the cutscene at the beginning of the level. The cutscene is a movie texture that plays until a coroutine eliminates the cutscene setup and instantiates the whole level (I store levels in prefabs and instantiate the terrain and everything after the cutscene is finished). After that, a gameobject that was instantiated along with the level instantiates the players fighter, which uses the same code that was used to instantiate the cutscene. Here is the code.

    Code (CSharp):
    1.     public GameObject blackScreenOpener;
    2.     // Use this for initialization
    3.     void Start () {
    4.         //delay = movieAudio.time;
    5.         if(delay <= 0){
    6.         Instantiate (theObject,transform.position,transform.rotation);
    7.             Destroy (gameObject);
    8.         }else{
    9.             StartCoroutine("delayTime");
    10.            
    11.         }
    12.     }
    13.     public IEnumerator delayTime (){
    14.         if(cutSceneSetup){
    15.        
    16.             yield return new WaitForSeconds(delay);
    17.             Instantiate (theObject,transform.position,transform.rotation);
    18.             Destroy (cutSceneSetup);
    19.             Destroy (gameObject);
    20.             if(toolTip){
    21.                 toolTip.StartCoroutine("toolTip");
    22.             }
    23.             TweenAlpha opener = blackScreenOpener.AddComponent<TweenAlpha>();
    24.             opener.delay = 1;
    25.             //blackAlphaTween.enabled = true;
    26.             opener.to = 0;
    27.             opener.from = 1;
    28.         }else{
    29.             yield return new WaitForSeconds(delay);
    30.             Instantiate (theObject,transform.position,transform.rotation);
    31.             Destroy (gameObject);
    32.         }
    33.    
    34.     }
    35.    
    36.     // Update is called once per frame
    37.     void Update () {
    38.    
    39.         if(Input.GetMouseButtonDown(0) && cutSceneSetup || Input.GetKeyDown(KeyCode.Escape) && cutSceneSetup){
    40.             //print ("go");
    41.         Instantiate (theObject,transform.position,transform.rotation);
    42.             Destroy (cutSceneSetup);
    43.             Destroy (gameObject);
    44.             if(toolTip){
    45.                 toolTip.StartCoroutine("toolTip");
    46.             }
    47.             TweenAlpha opener = blackScreenOpener.AddComponent<TweenAlpha>();
    48.             opener.delay = 1;
    49.             //blackAlphaTween.enabled = true;
    50.             opener.to = 0;
    51.             opener.from = 1;
    52.         }
    53.    
    54.     }
    55. }
    Then I was able to fix the bug on my machine by eliminating a script for the third person camera that aloud the camera to orbit around the aircraft. Here is what that code looked like.

    Code (CSharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class lookAroundOrbit: MonoBehaviour {
    7.  
    8.     public float horizontalSpeed = 2.0F;
    9.     public float verticalSpeed = 2.0F;
    10.     public Transform originalPositionObject;
    11.  
    12.     void FixedUpdate() {
    13.  
    14.         if(Input.GetMouseButton (2)){
    15.         float h = horizontalSpeed * Input.GetAxis("Mouse X");
    16.         float v = verticalSpeed * Input.GetAxis("Mouse Y");
    17.  
    18.         transform.Rotate(v, h, 0);
    19.             Vector3 temp = transform.localEulerAngles;
    20.         //    temp.z = 0;
    21.         //    transform.localEulerAngles = temp;
    22.  
    23.             //transform.rotation =
    24.                 //Quaternion.Lerp (transform.rotation, Quaternion.Euler(h,v,0),  1f);
    25.  
    26.                 }else{
    27.             transform.rotation =
    28.                 Quaternion.Lerp (transform.rotation, originalPositionObject.rotation,  0.1f);
    29.         }
    30.    
    31.             }
    32.  
    33.  
    34.  
    35. }
    36.  

    After that I thought everything was fine. Then I tried playing the game through steam on the other 2 computers and the bug was still there when the players decided not to skip the cutscene. The bug also happns on the 2 other computers when there is no cutscene instantiation at all and the players aircraft starts out in the scene without being instantiated at runtime.

    I started debugging the problem by eliminating gameobjects and code chunks from the players fighter and building a test scene and running the game on the other 2 computers. I started to eliminate the problem by adjusting when this line of code is called.

    MoveSpeed = Mathf.Lerp(MoveSpeed,Speed,Time.deltaTime);

    This piece of code makes the airplane slows down when the player not speeding up. I noticed by changing it to this, the airplane controls were usable on the other machines.

    if(MoveSpeed > Speed){
    //MoveSpeed = Mathf.Lerp(MoveSpeed,Speed,Time.deltaTime);

    }

    Speed is the minimum speed the airplane can travel. However, while carrying out my test, I was testing the game on the other machines on the home network, so the game was not completely installed on the other machines. I copied the files from the network onto the computers themselves, and the bug came back again, regardless of the changes I made.

    Here are the two scripts that is driving the airplane. FlightSystem.cs is used for both player and AI planes.

    FlightSystem.cs

    Code (CSharp):
    1. //[RequireComponent(typeof(BoxCollider))]
    2. [RequireComponent(typeof(DamageManager))]
    3. [RequireComponent(typeof(WeaponController))]
    4.  
    5.  
    6. public class FlightSystem : MonoBehaviour {
    7.    
    8.     public float Speed = 50.0f;
    9.     public float SpeedMax = 100;
    10.     public float afterburnSpeed = 80;
    11.     public float MoveSpeed = 10;
    12.     public float RotationSpeed = 1.0f;
    13.     public float TurnSpeed = 2;
    14.     public float SpeedPitch = 1;
    15.     public float SpeedRoll = 1;
    16.     public float SpeedYaw = 1;
    17.     public float DampingTarget = 10.0f;
    18.     public bool AutoPilot = false;
    19.     public bool AIControlled = false;
    20.     public ParticleSystem [] afterburnEffects;
    21.     public  ParticleEmitter [] ellipsoidEmitters;
    22.     public Light[] afterburnLights;
    23.     public float afterburnLightChangeSpeed;
    24.     public float afterburnLightIntensity;
    25.     public float particleAfterBurnAmount = 60;
    26.     public float enginePitchMax = 1.6f;
    27.     public AudioSource afterburnerAudio;
    28.  
    29.  
    30.  
    31.     //[HideInInspector]
    32.     public bool FollowTarget = true;
    33.     [HideInInspector]
    34.     public Vector3 PositionTarget = Vector3.zero;
    35.     [HideInInspector]
    36.     public DamageManager DamageManage;
    37.     [HideInInspector]
    38.     public WeaponController WeaponControl;
    39.    
    40.     private Vector3 positionTarget = Vector3.zero;
    41.     private Quaternion mainRot = Quaternion.identity;
    42.     [HideInInspector]
    43.     public float roll = 0;
    44.     [HideInInspector]
    45.     public float pitch = 0;
    46.     [HideInInspector]
    47.     public float yaw = 0;
    48.    
    49.    
    50.     void Start ()
    51.  
    52.  
    53.     {
    54.         MoveSpeed = SpeedMax;
    55.        
    56.  
    57.         if(AIControlled == true){
    58.         FollowTarget = true;
    59.         }
    60.         //transform.localEulerAngles = transform.localEulerAngles;
    61.         DamageManage = this.gameObject.GetComponent<DamageManager>();
    62.         WeaponControl = this.gameObject.GetComponent<WeaponController>();
    63.     }
    64.  
    65.     void FixedUpdate()
    66.     {
    67.  
    68.  
    69.         if(AIControlled != true){
    70.  
    71.  
    72. //            print (MoveSpeed);
    73.             if(MoveSpeed > afterburnSpeed){
    74.  
    75.                 if(afterburnLights[0].intensity >= particleAfterBurnAmount){
    76.                 foreach(ParticleSystem system in afterburnEffects){
    77.                     system.enableEmission = true;
    78.                     }
    79.                 }
    80.  
    81.            
    82.  
    83.                 if(afterburnLights[0].intensity >= particleAfterBurnAmount){
    84.                 foreach(ParticleEmitter emitter in ellipsoidEmitters){
    85.                     emitter.emit  = true;
    86.                 }
    87.  
    88.                 }
    89.                 //afterburnObject = Instantiate (afterburnEffects,transform.position,transform.rotation);
    90.            
    91.             }else if(MoveSpeed < afterburnSpeed){
    92.                 if(afterburnLights[0].intensity < particleAfterBurnAmount ){
    93.                 foreach(ParticleSystem system in afterburnEffects){
    94.                     system.enableEmission = false;
    95.                     }
    96.                 }
    97.  
    98.            
    99.                 if(afterburnLights[0].intensity < particleAfterBurnAmount  ){
    100.                 foreach(ParticleEmitter emitter in ellipsoidEmitters){
    101.                     emitter.emit = false;
    102.                     }
    103.                 }
    104.             }
    105.  
    106.  
    107.             /*
    108.         if(Input.GetMouseButton(2)){
    109.             AutoPilot = true;
    110.         }
    111.        
    112.         if(Input.GetMouseButtonUp(2)){
    113.             AutoPilot = false;
    114.         }
    115. */
    116.         }
    117.         if(!this.rigidbody)
    118.             return;
    119.  
    120.         Quaternion AddRot = Quaternion.identity;
    121.         Vector3 velocityTarget = Vector3.zero;
    122.        
    123.         if(AutoPilot){
    124.             if(FollowTarget){
    125.                 positionTarget = Vector3.Lerp(positionTarget,PositionTarget,Time.fixedDeltaTime * DampingTarget);
    126.                 Vector3 relativePoint = this.transform.InverseTransformPoint(positionTarget).normalized;
    127.                 mainRot = Quaternion.LookRotation(positionTarget - this.transform.position);
    128.                 rigidbody.rotation = Quaternion.Lerp(rigidbody.rotation,mainRot,Time.fixedDeltaTime * RotationSpeed);
    129.                 this.rigidbody.rotation *= Quaternion.Euler(-relativePoint.y * 0.2f,0,-relativePoint.x * 5);
    130.                 //this.rigidbody.rotation *= Quaternion.Euler (-relativePoint.y * 1, 0, -relativePoint.x * 10);
    131.  
    132.  
    133.  
    134.  
    135.  
    136.             }
    137.             velocityTarget = (rigidbody.rotation * Vector3.forward) * (Speed + MoveSpeed);
    138.         }else{
    139.             AddRot.eulerAngles = new Vector3(pitch, yaw, -roll);
    140.                 mainRot *= AddRot;
    141.             rigidbody.rotation = Quaternion.Lerp(rigidbody.rotation,mainRot,Time.fixedDeltaTime * RotationSpeed);
    142.             velocityTarget = (rigidbody.rotation * Vector3.forward) * (Speed + MoveSpeed);
    143.            
    144.         }
    145.         rigidbody.velocity = Vector3.Lerp(rigidbody.velocity,velocityTarget,Time.fixedDeltaTime);
    146.        
    147.         yaw = Mathf.Lerp(yaw,0,Time.deltaTime);
    148.  
    149.         if(MoveSpeed > Speed){
    150.         MoveSpeed = Mathf.Lerp(MoveSpeed,Speed,Time.deltaTime);
    151.  
    152.         //MoveSpeed = Mathf.MoveTowards(MoveSpeed,Speed,1);
    153.         }
    154.  
    155.         }
    156.    
    157.    
    158.  
    159.     public void AxisControl(Vector2 axis){
    160.         roll = Mathf.Lerp(roll,Mathf.Clamp(axis.x,-2,2) * SpeedRoll,Time.deltaTime);
    161.         pitch = Mathf.Lerp(pitch,Mathf.Clamp(axis.y,-1,1) * SpeedPitch,Time.deltaTime);
    162.  
    163.         //roll = Mathf.MoveTowards(roll,Mathf.Clamp(axis.x,-2,2) * SpeedRoll,SpeedRoll * Time.deltaTime);
    164.         //pitch = Mathf.MoveTowards(pitch,Mathf.Clamp(axis.y,-1,1) * SpeedPitch, SpeedPitch * Time.deltaTime);
    165.  
    166.  
    167.         //roll = Mathf.MoveTowards(roll,Mathf.Clamp(axis.x,-2,2) * SpeedRoll,Time.deltaTime);
    168.         //pitch = Mathf.MoveTowards(pitch,Mathf.Clamp(axis.y,-1,1) * SpeedPitch,Time.deltaTime);
    169.  
    170.  
    171.     }
    172.    
    173.     public void TurnControl(float turn){
    174.         yaw += turn * Time.deltaTime * SpeedYaw;
    175.  
    176.  
    177.     }
    178.    
    179.     public void SpeedUp(float joystickSpeed){
    180.  
    181.  
    182.         print ("speedup");
    183.         if(Input.GetJoystickNames().Length > 0 && AIControlled != true){
    184.             MoveSpeed = Mathf.Lerp(MoveSpeed,SpeedMax,Time.deltaTime * joystickSpeed);
    185.            
    186.  
    187.             foreach(Light afterburnLight in afterburnLights){
    188.                 afterburnLight.intensity = Mathf.Lerp (afterburnLight.intensity, afterburnLightIntensity,joystickSpeed * Time.deltaTime);
    189.                
    190.                
    191.             }
    192.            
    193.            
    194.             if(AIControlled != true){
    195.                 if(MoveSpeed >= afterburnSpeed ){
    196.                    
    197.                     afterburnerAudio.volume = Mathf.Lerp (afterburnerAudio.volume, 0.5f,joystickSpeed* Time.deltaTime);
    198.                     audio.volume = Mathf.Lerp (audio.volume,0.1f,joystickSpeed * Time.deltaTime);
    199.                     audio.pitch = Mathf.Lerp (audio.pitch, enginePitchMax,joystickSpeed * Time.deltaTime);
    200.                 }else{
    201.                     audio.pitch = Mathf.Lerp (audio.pitch, enginePitchMax,joystickSpeed -5 * Time.deltaTime);
    202.                     audio.volume = Mathf.Lerp (audio.pitch,1,joystickSpeed * Time.deltaTime);
    203.                 }
    204.                
    205.             }
    206.  
    207.         }
    208.         else{
    209.         MoveSpeed = Mathf.Lerp(MoveSpeed,SpeedMax,Time.deltaTime * 10);
    210.        
    211.  
    212.         foreach(Light afterburnLight in afterburnLights){
    213.             afterburnLight.intensity = Mathf.Lerp (afterburnLight.intensity, afterburnLightIntensity,afterburnLightChangeSpeed * Time.deltaTime);
    214.            
    215.  
    216.         }
    217.  
    218.  
    219.         if(AIControlled != true){
    220.             if(MoveSpeed >= afterburnSpeed ){
    221.  
    222.             afterburnerAudio.volume = Mathf.Lerp (afterburnerAudio.volume, 0.5f,afterburnLightChangeSpeed * Time.deltaTime);
    223.                     audio.volume = Mathf.Lerp (audio.volume,0.1f,afterburnLightChangeSpeed * Time.deltaTime);
    224.                     audio.pitch = Mathf.Lerp (audio.pitch, enginePitchMax,afterburnLightChangeSpeed * Time.deltaTime);
    225.             }else{
    226.                     audio.pitch = Mathf.Lerp (audio.pitch, enginePitchMax,afterburnLightChangeSpeed * Time.deltaTime);
    227.                     audio.volume = Mathf.Lerp (audio.pitch,1,afterburnLightChangeSpeed * Time.deltaTime);
    228.             }
    229.            
    230.         }
    231.  
    232.         }
    233.  
    234.     }
    235.  
    236.      public void SpeedDown(){
    237.         print ("speeddown");
    238.  
    239.    
    240.         foreach(Light afterburnLight in afterburnLights){
    241.             afterburnLight.intensity = Mathf.Lerp (afterburnLight.intensity, 0f,afterburnLightChangeSpeed * Time.deltaTime);
    242.            
    243.  
    244.         }
    245.  
    246.         audio.pitch = Mathf.Lerp (audio.pitch, 1,afterburnLightChangeSpeed * Time.deltaTime);
    247.     audio.volume = Mathf.Lerp (audio.volume,1,afterburnLightChangeSpeed * Time.deltaTime);
    248.  
    249.         if(AIControlled != true){
    250.             afterburnerAudio.volume = Mathf.Lerp (afterburnerAudio.volume, 0f,afterburnLightChangeSpeed * Time.deltaTime);
    251.         }
    252.  
    253.     }
    254.    
    255.     void Update(){
    256.        
    257.     }
    258.  
    259.  
    260. }



    PlayerController.cs

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     FlightSystem flight;
    7.     public bool Active = true;
    8.     public ModernIndicator displayScreen;
    9.     public int mouseSensitivityY = 1;
    10.     public int mouseSensitivityX = 1;
    11.     public UILabel controllerWarningLabel;
    12.  
    13.  
    14.     void Awake () {
    15.         GameObject.Find ("MS_backY").GetComponent<ngui_button_MS>().theController = this;
    16.         GameObject.Find ("MS_forwardY").GetComponent<ngui_button_MS>().theController = this;
    17.         GameObject.Find ("MS_backX").GetComponent<ngui_button_MS>().theController = this;
    18.         GameObject.Find ("MS_forwardX").GetComponent<ngui_button_MS>().theController = this;
    19.  
    20.         mouseSensitivityY = PlayerPrefs.GetInt("mouseSensitivityY");
    21.         mouseSensitivityX = PlayerPrefs.GetInt ("mouseSensitivityX");
    22.  
    23.         Time.timeScale = 1;
    24.         scoreKeeperScript scoreKeeper = GameObject.Find ("level_Mission").GetComponent <scoreKeeperScript>();
    25.         scoreKeeper.theToolTipScript.controller = this;
    26.         scoreKeeper.thePauseControl.controller = this;
    27.         scoreKeeper.thePauseControl.modernScreen = displayScreen;
    28.  
    29.         flight = this.GetComponent<FlightSystem>();
    30.         controllerWarningLabel = scoreKeeper.controllerWarningText;
    31.  
    32.     }
    33.    
    34.     void Update () {
    35.        
    36.         if(Input.GetKeyDown(KeyCode.Alpha1)){
    37.             flight.WeaponControl.changeWeapon(0);
    38.         }
    39.         if(Input.GetKeyDown(KeyCode.Alpha2)){
    40.             flight.WeaponControl.changeWeapon(1);
    41.         }
    42.         if(Input.GetKeyDown(KeyCode.Alpha3)){
    43.             flight.WeaponControl.changeWeapon(2);
    44.         }
    45.  
    46.         /*
    47.         if(Input.GetMouseButton(2)){
    48.             Active = false;
    49.         }
    50.        
    51.         if(Input.GetMouseButtonUp(2)){
    52.             Active = true;
    53.         }
    54.  
    55. */
    56.         if(!flight || !Active)
    57.             return;
    58.        
    59.        
    60.         Screen.lockCursor = true;
    61.  
    62.  
    63.         if(Input.GetJoystickNames().Length > 0) {
    64.             flight.AxisControl(new Vector2(Input.GetAxis("JoystickHorizontal") * mouseSensitivityX  ,Input.GetAxis("JoystickVertical") * mouseSensitivityY ));
    65.  
    66.             //if(Input.GetAxis ("JoystickZaxis")){
    67.                 flight.TurnControl(Input.GetAxis ("JoystickZaxis") * -1);
    68.             flight.SpeedUp(Input.GetAxis ("JoystickAxis4") * 10);
    69.  
    70.  
    71.         }else{
    72.             flight.AxisControl(new Vector2(Input.GetAxis("Mouse X") * mouseSensitivityX  ,Input.GetAxis("Mouse Y") * mouseSensitivityY ));
    73.             //flight.AxisControl(new Vector2(Input.GetAxis("Mouse X")   ,Input.GetAxis("Mouse Y")  ));
    74.         }
    75.  
    76.    
    77.  
    78.         if(Input.GetKey(KeyCode.A)|| Input.GetKey (KeyCode.JoystickButton8)){
    79.             flight.TurnControl(-1);
    80.         }
    81.         if(Input.GetKey(KeyCode.D) || Input.GetKey (KeyCode.JoystickButton9)){
    82.             flight.TurnControl(1);
    83.         }
    84.         if(Input.GetKey(KeyCode.W) || Input.GetKey (KeyCode.JoystickButton2)){
    85.             flight.SpeedUp(10);
    86.         }else{
    87.             if(flight.MoveSpeed > flight.Speed ){
    88.  
    89.             flight.SpeedDown ();
    90.             }
    91.         }
    92.  
    93.    
    94.  
    95.  
    96.         if(Input.GetButton("Fire1")){
    97.             flight.WeaponControl.LaunchWeapon();
    98.  
    99.  
    100.         }
    101.  
    102.    
    103.  
    104.         if(Input.GetKeyDown(KeyCode.R) || Input.GetKeyDown (KeyCode.JoystickButton1)){
    105.             flight.WeaponControl.SwitchWeapon();
    106.         }
    107.  
    108.         if(Input.GetKeyDown(KeyCode.Joystick1Button2)){
    109.             flight.WeaponControl.SwitchWeapon();
    110.         }
    111.  
    112.         if(Input.GetAxis("Mouse X") * mouseSensitivityX > 0){
    113.            
    114.             if(Input.GetJoystickNames().Length > 0 ){
    115.            
    116.                 controllerWarningLabel.enabled = true;
    117.                 StartCoroutine("stopNotice");
    118.             }
    119.            
    120.            
    121.            
    122.         }
    123.  
    124.     }
    125.  
    126.     public IEnumerator stopNotice(){
    127.         yield return new WaitForSeconds(7);
    128.         controllerWarningLabel.enabled = false;
    129.        
    130.     }
    131. }
    132.  
     
  21. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Hey now, he can pay me if he wants. ;)

    @roger0, I can't read all of that right now, but PM me in 8 hours or so and I'll take a quick look tonight.
     
  22. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
  23. vintar

    vintar

    Joined:
    Sep 18, 2014
    Posts:
    90
    This can maybe cause problems on other computers as if the variable does not exist it wil be set to zero, but I haven't looked hard at the code yet.
     
  24. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Yep, PlayerPrefs should always be used with a default value, which can be specified as an extra parameter. So that could be something. When I played the tute I initially had no mouse input at all. After a few GUI screens I had input. I then closed the game and re-opened it and had input from the start. That could point to a preferences value that wasn't initially set.

    So, there is some part of the game's state which is set inconsistently depending on whether or not the cutscene plays.

    Where are your calculated roll and pitch values actually used? SpeedRoll and SpeedPitch aren't directly setting speeds, there, by the way. They will effect the speed, but only indirectly by modifying the distance to a point that will never be reached.
     
  25. vintar

    vintar

    Joined:
    Sep 18, 2014
    Posts:
    90
    looking again I see this too :
    and so maybe if the cut-scene is skipped you may be playing at "slower than normal" speed and it could seem like you are turning slower.
     
    angrypenguin likes this.
  26. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    I noticed the bug only happens when the game quality is set to lower than good, so I fixed it by disabling fastest, fast, and simple quality settings!

    The airstrike starter kit demo (which is the package I used to start building the game) also has this problem with the quality settings. I am relieved that I found a solution to this bug, however, I am still not sure what the cause is, so I'm a little nervous as to where it may pop up next.
     
  27. vintar

    vintar

    Joined:
    Sep 18, 2014
    Posts:
    90
    Really strange, you would imagine it to be the other way and get slower the higher the setting...
    Its almost as if they have a custom built VSync :D