- Home /
Ai turning problem on Android - Question solved
Hello,
I am currently working on the ai for a racing game, and I have come across a problem. Before each turn I have a waypoint telling the car the angle of the turn it has to make. In the editor I got everything working just fine, but as soon as I make an Android build and try it on my phone it doesn't work as expected; the ai makes to small turns, causing him to go off-track.
The game runs at 1800 fps in editor and 100-400 on my android phone.
The ai turns by using transform.Translate(), I don't know if this causes problems on android.
Thanks in advance
EDIT: It was working quite decent when I updated the amount the car had to turn in the Update function but then I changed that to FixedUpdate and since then it was really terrible.
EDIT2: some additional info.
EDIT3: turned out the move() function was called in the Update() instead of the FixedUpdate().. changing it worked.
this is the function that determines the amount it turns. variable turn is the angle it has to turn to make the corner. variable turned is the amount it has turned so far. variable turnamount is the amount it is going to turn this frame. variable turnrate is the amount it is able to turn in a second
function calculateTurn(){
if(turned > turn){
turnamount = turned - turn+1;
turn = 0;
turned = 0;
}
if(turned == turn){
turn = 0;
turned = 0;
turnamount = 0;
}
if(turn == 0){
return;
}
else{
turnamount += turnrate*Time.deltaTime;
turned += turnamount;
}
}
this is the function that actually turns and moves the car
function move(){
if(turndirection == 1){
transform.Rotate(0, turnamount, 0);
}
else{
transform.Rotate(0, -turnamount, 0);
}
turnamount = 0;
transform.Translate(0, 0, speed*Time.deltaTime);
}
Seems like your turning update is frame-dependent. When it should be time-dependent. Are you calculating the turn amount per frame with Time.deltaTime?
http://docs.unity3d.com/Documentation/ScriptReference/Time-deltaTime.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613080622im_/https://answers.unity.com/themes/thub/images/avi.jpg)