Hi guys, I have 300 cars on my game, but I get some bugs on moving. P1. When the front car is stopped, the rear car keep moving back and forth. P2. When the front car is stopped, the rear car sometimes stops and (problem 1) or sometimes moves over the first car. P3. The rotation part of the car doesn't work very good. If angle between current Point and next point is big, the car rotates instant, if I try to smooth the rotate, the car miss the next point and start rotating over that point. My Car: My Code: Code (CSharp): private void drive() { transform.position += transform.forward * Time.smoothDeltaTime * CurrentSpeed; var direction = _currentWayPoint.transform.position - transform.position; transform.rotation = Quaternion.Lerp(transform.rotation,Quaternion.LookRotation(direction), _turnSpeed * Time.deltaTime); if (ForcedBraking || IsRed) { turnONBackLights(); CurrentSpeed = 0; } else if (IsCarAhead) { turnONBackLights(); CurrentSpeed = (CurrentSpeed < 4) ? 0 : CurrentSpeed * MaxSpeed * Time.deltaTime; } else if(CurrentSpeed < MaxSpeed ) { CurrentSpeed += MaxSpeed *Time.deltaTime; turnOFFBackLights(); } }
So, just to focus on your P1 (from original post above) for now. Are you saying that 9 cars in a row stopped at a red light work fine but adding a tenth car makes that tenth car move about whilst the original 9 remain stationary?
To clarify my question, this is what I am asking: There are 8 cars stopped in a row. None of them are moving. Another car (number 9) drives up behind the 8th car and stops as expected. Another car (number 10) drives up behind the 9th car. So, every time you run this test, step 2 always happens as expected. But with step 3 sometimes the car stops as expected but sometimes does not. Is all that correct? If not, which part do I have wrong?
Yes, is correct. I changed the order and now the only problem is I have low fps fo 300 cars. Code (CSharp): private void drive() { if (ForcedBraking || IsRed) { turnONBackLights(); CurrentSpeed = 0; } else if (IsCarAhead) { turnONBackLights(); CurrentSpeed -= (CurrentSpeed < 4) ? 0 : CurrentSpeed*(1 - MaxSpeed * Time.deltaTime); } else { if (CurrentSpeed < MaxSpeed) CurrentSpeed += MaxSpeed * Time.deltaTime; //transform.position += transform.forward * Time.smoothDeltaTime * CurrentSpeed; _rb.MovePosition(transform.position + (transform.forward * CurrentSpeed * Time.deltaTime)); var direction = _currentWayPoint.transform.position - transform.position; transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(direction), _turnSpeed * Time.deltaTime); turnOFFBackLights(); } }