Hi,
I wish to create a simulation of tank movement. as it move forward, the turret will be able to turn right and left when the correspondent key is being pressed.
But how do I make the turret to slowly return back to body_ori (facing in front back again) when I release the key? what I have here in the code, makes the turret to reappear to original position in a flash. also, why my turret does not turn smoothly like in TIME_EVENT? Is it normal in KEYDOWN_EVENT and KEYUP_EVENT?
Code:
def onkeydown(key):
if key == viz.KEY_RIGHT:
view.rotate(0,1,0,turn_speed*viz.elapsed(),viz.BODY_ORI,viz.REL_PARENT)
elif key == viz.KEY_LEFT:
view.rotate(0,1,0,-turn_speed*viz.elapsed(),viz.BODY_ORI,viz.REL_PARENT)
viz.callback(viz.KEYDOWN_EVENT,onkeydown)
def onKeyUp(key):
if key == viz.KEY_RIGHT:
view.reset(viz.HEAD_ORI | viz.BODY_ORI)
elif key == viz.KEY_LEFT:
view.reset(viz.HEAD_ORI | viz.BODY_ORI)
viz.callback(viz.KEYUP_EVENT,onKeyUp)