I am stuck with some coding. I know the problem but I don’t know how to solve it.
My wheel is turning according to the velocity.
Now I need the wheel to slowly stop spinning when not in contact with the ground.
The Ray sensor checks if there is contact with the ground.
The rotation when in contact works fine but I don’t know how to save the last value when getting off the ground and loading it into the “else” loop.
Here is the code:
import GameLogic import math cont=GameLogic.getCurrentController() own=cont.owner board = own.scene.objects["Board"] boardVel = board["velocity"] rayEmpty= own.scene.objects["WheelRay"] ray = rayEmpty.sensors["Ray"] vel = boardVel if ray.positive: velWheel = (vel*0.1)*-1 rotationVel = [velWheel, 0.0, 0.0] own.applyRotation(rotationVel, 1) own["prop"] = velWheel else: prop = own["prop"] velWheel = prop + 0.1 rotationVel = [velWheel, 0.0, 0.0] own.applyRotation(rotationVel, 1)
I tried to solve it before with the game logic states with almost good results (the property was already decreasing while not in contact with the ground)
But I couldn’t load the property again into the code.
The code above is without game logic states, but I don’t know how to save the last value of the velWheel variable after exiting the positive if loop.
Thanks for any help!