I am trying to build a kind of tank, and for that I made a Body object, having a child Turret. The turret follows the mouse's X axis, and I would like the body of the tank to smoothly rotate towards the turret's rotation while in motion (ie. when w or s is pressed).
However the tank should not rotate while stopped, or moving sideways (a or d then).
I have this code:
import bge, math scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() obj = cont.owner child = obj.children['Turret'] rot = obj.localOrientation.to_euler() rotChild = child.localOrientation.to_euler() rot += rotChild / 2 obj.localOrientation = rot.to_matrix()
It works, but not as intended; the roation of the body is abrupt, and it only rotates for the instant I press the key (w or s) instead of the whole time the key is down.
I know my code is partly in fault, maybe I should access the body's angular velocity, but I don't know how to.