- Home /
The question is answered, right answer was accepted
AI car does not move anymore?
Hey so I am making a basic car racing game in. All I have right now is a track, a mini map, a player car and an AI car which follows a set of way points around the track. Yesterday I put in a few lines of code to get the value of the player car's speed (just a numerical reading, not making a needle speedometer). Now as soon as my game starts the speedometer works fine but the AI car is just stuck at the starting position now (the player car works fine). The wheels still spin (smoke particle effect is visible) but the car does not move. Here is the portion of my code (P.S both of the cars which i am using are taken from the "Standard Assets" package of Unity)
private void CapSpeed() { float speed = m_Rigidbody.velocity.magnitude; switch (m_SpeedType) { case SpeedType.MPH:
speed *= 2.23693629f;
SpeedDisplay.GetComponent<Text>().text = speed.ToString();
if (speed > m_Topspeed)
m_Rigidbody.velocity = (m_Topspeed/2.23693629f) * m_Rigidbody.velocity.normalized;
break;
case SpeedType.KPH:
speed *= 3.6f;
SpeedDisplay.GetComponent<Text>().text = speed.ToString();
if (speed > m_Topspeed)
m_Rigidbody.velocity = (m_Topspeed/3.6f) * m_Rigidbody.velocity.normalized;
break;
}
my best guess would be that m_Topspeed is 0. Did you check for that?
No it is not. The funny thing is that as soon as i comment out the line ( SpeedDisplay.GetComponent().text = speed.ToString(); ) the AI car works perfectly again. How does this line of code affect the motion of the car? That's the bit I do not understand.
Follow this Question
Related Questions
Cannot make initial speed for the Player car using AIDriverToolkit 0 Answers
Car steering to target relative to speed smoothly 0 Answers
Destroyed car styled need for speed? 0 Answers
Error car game 0 Answers