Search Unity

Rotating bike at any speed can't do it with my code any suggestion

Discussion in 'Scripting' started by idcanu, Mar 26, 2019.

  1. idcanu

    idcanu

    Joined:
    Jul 3, 2017
    Posts:
    14
    Code (CSharp):
    1.  
    2.  
    3.     private void FixedUpdate()
    4.     {
    5.         RearWheelRPM = coll_rearWheel.rpm;
    6.         frontWheelRPM = coll_frontWheel.rpm;
    7.  
    8.         EngineRPM = coll_rearWheel.rpm * GearRatio[CurrentGear];
    9.  
    10.         if (EngineRPM > EngineRedline)
    11.         {
    12.             EngineRPM = MaxEngineRPM;
    13.         }
    14.  
    15.         ESP = outsideControls.ESPMode;
    16.        
    17.         if (!crashed)
    18.         {
    19.            RB.drag = RB.velocity.magnitude / 210f * airRes;//210f
    20.            RB.angularDrag = (7f + RB.velocity.magnitude / 20f);//7 default
    21.         }
    22.  
    23.      
    24.         bikeSpeed = Mathf.Round((RB.velocity.magnitude * 3.6f) * 10f) * 0.1f;//0.1 Default //10 //3.6
    25.      
    26.         veloct =  RB.velocity.magnitude;
    27.         RND = Mathf.Round(veloct);
    28.  
    29.  
    30.      
    31.         if (!crashed && gameScenario.GetComponent<mobileControls>().IsTouchContinue && !isReverseOn )
    32.         {
    33.             Debug.Log("Is still Continue");
    34.             Accelarate_BK();
    35.         }
    36.         else
    37.         {
    38.            RearSuspensionRestoration();
    39.         }
    40.  
    41.  
    42.         tempMaxWheelAngle = whellbarRestrictCurve.Evaluate(bikeSpeed);
    43.  
    44.         if (!crashed && outsideControls.Horizontal != 0)
    45.         {
    46.             coll_frontWheel.steerAngle = tempMaxWheelAngle * outsideControls.Horizontal * 1.52f ;
    47.             steeringWheel.rotation = coll_frontWheel.transform.rotation *
    48.                 Quaternion.Euler(0f, coll_frontWheel.steerAngle, coll_frontWheel.transform.rotation.z);
    49.         }
    50.         else
    51.         {
    52.             coll_frontWheel.steerAngle = 0f;
    53.         }
    54.   }
    55.     void Accelarate_BK()
    56.     {
    57.         coll_frontWheel.brakeTorque = 0;
    58.         coll_rearWheel.motorTorque = EngineTorque * 1.2f;
    59.         meshRearWheeel.GetComponent<Renderer>().material.color = Color.green;
    60.         CoM.localPosition =
    61.             new Vector3(CoM.localPosition.x, normalCoM, 0.0f + tmpMassShift);
    62.         RB.angularDrag = 7f;
    63.         RB.centerOfMass = CoM.localPosition;
    64.     }
    65. }
    66.  
    The Bike control is not working properly bike is using rigidbody to rotate which is what is making the bike rotate only up to certain degree and that too is dependent on speed i want to make bike's rotation independent of it's speed will it be possible to do it with rigidbody or without rigidbody. Any suggestion are appreciated.
     
    Last edited: Mar 27, 2019
  2. Cyber-Dog

    Cyber-Dog

    Joined:
    Sep 12, 2018
    Posts:
    352
    You probably wont get a response if you just dump a whole CS file into a post. Nobody wants to read and do all the work for you ;)

    Isolate your issue and post that part of the code, explaining were its going wrong.
     
  3. idcanu

    idcanu

    Joined:
    Jul 3, 2017
    Posts:
    14
    @Cyber-Dog
    i have isolated the needed part , do you have any solution for this problem in rotation of my bike with speed ,
    thanks for the suggestion earlier, i am very new to unity.