When I right click my mouse I want my camera to go from 32 mill to 50 or so. I tried to insert a key frame while having the camera selected. One key frame at 32 and a few frames later at 50.
Note, this is a first person shooter so when not aiming I want him to be at 32 mill and when he gets to the end of the aim animation I want the camera to be at 50.
Considering you use one Mouse Sensor and one […]-pulsed Always Sensor, connect them both to this Script:
from bge import logic as g
lens=g.getCurrentScene().active_camera.lens
if g.getCurrentController().sensors["Mouse"].positive:
lens+=(50-lens)*0.1
else:
lens+=(32-lens)*0.1
I don’t think that script works how you expected it to, C.A.
You can use this script, which I’ve tested. Add an Always sensor to your camera and enable True pulse on it (the [’’’] button). Attach it to a Python controller using this script:
from bge import logic, events
# Adjust these values to your preference
ZOOM_SPEED = 2
ZOOMED_IN = 50
ZOOMED_OUT = 34
def main():
cont = logic.getCurrentController()
own = cont.owner
# Get mouse and right click
mouse = logic.mouse.events
right = mouse[events.RIGHTMOUSE] == 1
# Create property
if 'zoomed' not in own:
own['zoomed'] = False
# Toggle zoom mode
if right:
own['zoomed'] = not own['zoomed']
# Adjust camera lens
if own['zoomed']:
if own.lens < ZOOMED_IN:
own.lens += ZOOM_SPEED
else:
if own.lens > ZOOMED_OUT:
own.lens -= ZOOM_SPEED
main()