Car python script, wheel rotation problem

I have a little problem with setting up a script for rotating the wheels of my car correctly. I did most of the script with a tutorial but it didn’t include spinning the wheels, the correctly working part (of the script)… is the part from the tutorial…

The problem is, when I’m driving my car in BGE, the wheels don’t stop spinning when I release up or down arrow, the starting forward/backward seems to work more or less, but not exactly as it should. Also when driving and changing from back to forward or from forward to back, the wheel does seem to change spinning side, however, they don’t stop spinning when my car stops.

Well anyway, if someone with some python and logic knowledge could look at it, here’s the file:

car-script-wheel-fail.blend (553 KB)

The not correctly working code is between the ####### lines

Change in line 51 if spin[0] > 0: to if spin[1] > 0: and line 53 if spin[0] < 0: to if spin[1] < 0:.
For .dRot you don’t need to use mathutils.Vector() you can write a.actuators[0].dRot = [spin[0],spin[1] + 0.02,spin[2]]

Thanks! It’s working a lot better now, still needs some fine tuning because it’s not 100% correct yet but thanks a lot already.

I was thinking: Maybe I should get the speed of object “Car” and use it as a variable to calculate the wheel spinning, however, I have no clue how to get that variable in python. (Yes, I’m a PythonNoob) I believe that doing it like that would give a much better result, as if the speed is 0, the wheel wouldn’t spin at all.

Now at least the wheel stops spinning when the car stops, but when I drive fast the wheel goes “crazy spinning” and when the car stops than it takes a little while before it stops spinning again, acting a bit weird.

working-01.blend (551 KB)

I changed your script.

Attachments

working-01.blend (507 KB)

Thanks man! Think I already met the next problem with the camera setup this time… but that will be for tomorow.