Hey guys,
I have found a cool mouselook script in Martinsh’ flare playground, and it works perfectly as is, but I was wondering if anyone has a spare few minutes, if you could help me out to add a few extra lines, to limit the up/down rotation of the camera (rotation of the empty that the camera is parented to)
Script attached to this post.
#Blender Game Engine 2.55 Simple Camera Look#Created by Mike Pan: mikepan.com
# Use mouse to look around
# W,A,S,D key to walk around
# E and C key to ascend and decend
from bge import logic as G
from bge import render as R
from bge import events
from mathutils import *
scene = G.getCurrentScene()
yaw = scene.objects["Empty"]
speed = 0.08 # walk speed
sensitivity = 0.003 # mouse sensitivity
smooth = 0.75 # mouse smoothing (0.0 - 0.99)
cont = G.getCurrentController()
owner = cont.owner
Mouse = cont.sensors["Mouse"]
w = R.getWindowWidth()//2
h = R.getWindowHeight()//2
screen_center = (w, h)
# center mouse on first frame, create temp variables
if "oldX" not in owner:
R.setMousePosition(w + 1, h + 1)
owner["oldX"] = 0.0
owner["oldY"] = 0.0
else:
scrc = Vector(screen_center)
mpos = Vector(Mouse.position)
x = scrc.x-mpos.x
y = scrc.y-mpos.y
# Smooth movement
owner['oldX'] = (owner['oldX']*smooth + x*(1.0-smooth))
owner['oldY'] = (owner['oldY']*smooth + y*(1.0-smooth))
x = owner['oldX']* sensitivity
y = owner['oldY']* sensitivity
# set the values
owner.applyRotation([0, 0, x], False)
yaw.applyRotation([y, 0, 0], True)
# Center mouse in game window
R.setMousePosition(*screen_center)
keyboard = G.keyboard.events
# KEY BINDINGS
kbleft = events.DKEY # Replace these with others, if you wish
kbright = events.AKEY # An example would be 'events.WKEY, DKEY, SKEY, and AKEY
kbup = events.SKEY
kbdown = events.WKEY #
##################
if not 'moveinit' in owner:
owner['moveinit'] = 1
owner['mx'] = 0.0
owner['my'] = 0.0
#
#
#
# ~~SETTINGS~~ #
#
#
#
# Tweak these settings to fit your needs
owner['accel'] = 2.0 # Acceleration
owner['maxspd'] = 3.5 # Top speed
owner['friction'] = 0.75 # Friction percentage; set to 0.0 for immediate stop
owner['movelocal'] = 1 # Move on local axis?
if keyboard[kbleft]:
owner['mx'] += owner['accel']
elif keyboard[kbright]:
owner['mx'] -= owner['accel']
else:
owner['mx'] *= owner['friction']
if keyboard[kbup]:
owner['my'] += owner['accel']
elif keyboard[kbdown]:
owner['my'] -= owner['accel']
else:
owner['my'] *= owner['friction']
# Clamping
if owner['mx'] > owner['maxspd']:
owner['mx'] = owner['maxspd']
elif owner['mx'] < -owner['maxspd']:
owner['mx'] = -owner['maxspd']
if owner['my'] > owner['maxspd']:
owner['my'] = owner['maxspd']
elif owner['my'] < -owner['maxspd']:
owner['my'] = -owner['maxspd']
# Actual movement
owner.setLinearVelocity([owner['my'], owner['mx'], owner.getLinearVelocity()[2]], owner['movelocal'])
Is there any chance someone could implement that for me into this existing one?
OR
In a separate script - by getting worldOrientation
basically, I want to tell the empty, that when it’s over a certain positive value with it’s rotation, and below a negative value, to stop rotating. In this case, up and down with it’s local X axis.
Thank you in advance, should anyone care to help me out
Pete