- Home /
Question by
Bloke28 · Mar 31, 2018 at 02:24 AM ·
carvehiclestandard assets
Standard Asset Car won't shift past 3rd gear yet coding is set to 5 gears.
I'm using the standard asset car and it seems to have a bug which stops it shifting to 4th or 5th gear.. How can this be fixed? (Unity version Version 2017.4.0f1 (b5bd171ee9ba) Personal Wed, 14 Mar 2018 11:16:17 GMT Branch: 2017.3/release)
Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.Vehicles.Car;
public class GearManager : MonoBehaviour {
public static int GearsValue;
//public static int GlobalGears;
public GameObject GearsDisplay;
// Use this for initialization
// Update is called once per frame
void Update () {
//if(CarController.m)
GearsValue = CarController.m_GearNum + 1;
GearsDisplay.GetComponent<Text>().text = "Gears: " + GearsValue;
}
}
// Is the script to display gears to see.
Comment
[SerializeField] public static float m_Topspeed = 200; and public static int m_GearNum;
were my only changes to the carcontroller script where I believe the problem may lie?
A$$anonymous$$A both were made static
Best Answer
Answer by Bloke28 · Mar 31, 2018 at 04:10 AM
public Rigidbody objectToClock;
public float maxVelocity = 100f;
public float CurrentSpeednow;
private void Update()
{
CurrentSpeednow = objectToClock.velocity.magnitude / maxVelocity;
if (m_GearNum == 0 && CurrentSpeednow * 400 > (MaxSpeed / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 1; // 2nd gear
}
if (m_GearNum == 1 && (CurrentSpeednow * (400)) > (MaxSpeed*2 / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 2; // 3rd gear
}
if (m_GearNum == 2 && CurrentSpeednow * 400 > (MaxSpeed*3 / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 3; //4th gear
}
if (m_GearNum == 3 && CurrentSpeednow * 400 > (MaxSpeed*4 / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 4; //5th gear
}
if (m_GearNum == 4 && CurrentSpeednow * 400 > (MaxSpeed * 4.5 / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 5; //6th gear
}
if (m_GearNum >= 1 && CurrentSpeednow * 400 < (MaxSpeed / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 0; // 1nd gear downwards
}
if (m_GearNum >= 2 && CurrentSpeednow * 400 < (MaxSpeed*2 / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 1; // 2nd gear downwards
}
if (m_GearNum >= 3 && CurrentSpeednow * 400 < (MaxSpeed * 3 / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 2; // 3nd gear downwards
}
if (m_GearNum >= 4 && CurrentSpeednow * 400 < (MaxSpeed * 4 / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 3; // 4nd gear downwards
}
if (m_GearNum >= 5 && CurrentSpeednow * 400 < (MaxSpeed * 4.5 / NoOfGears)) // max 200/5 = 40
{
m_GearNum = 4; // 5th gear downwards
}
}
private void GearChanging()
{
/*
float f = Mathf.Abs(CurrentSpeed/MaxSpeed);
float upgearlimit = (1/(float) NoOfGears)*(m_GearNum + 1);
float downgearlimit = (1/(float) NoOfGears)*m_GearNum;
if (m_GearNum > 0 && f < downgearlimit)
{
m_GearNum--;
}
if (f > upgearlimit && (m_GearNum < (NoOfGears - 1)))
{
m_GearNum++;
}
*/
}
Rewrote the code and it works now :P
Your answer
![](https://koobas.hobune.stream/wayback/20220612155724im_/https://answers.unity.com/themes/thub/images/avi.jpg)