mouse script:need 1

ok
i need a mouselook script for my FPS game.
i look all over the place and i couldent find 1.
most of u know what i mean.
so Thanks :smiley:

umm, I don’t believe you looked very hard

but anway, I have 3 [or 4?] mouselook scripts

but, rather than choosing one for you, have a look at
http://home.earthlink.net/~nwinters99/temp/fps_controls.blend

the other scripts are in the same directory

i just need the code
if u could give me that :smiley:

the setup is very important, so it wouldn’t do you much good

but if you want to try anyway:

#### MOUSESCRIPT 2 ####
# author: z3r0_d (Nick Winters)
# license: public domain
#######################
#  this is a variation on my other mouse scripts
#  it is intended to act as a fps camera, except it uses
#  2 objects for the rotation instead of one
#  the object the script is in only rotates around its z axis
#  the object refrenced by an actuator linked to this script
#  will only rotate around it's x axis. this will allow the 
#  movement to work properly with the direction being faced
#  by for example allowing a local motion of the base object
#  to not be into the sky when looking up or into the ground
#  when looking down
#######################
# setup:
# Logic Bricks:
#	sensors:
#	 	m_move  			A mouse movement sensor pulses turned off
#	actuators:
#		[doesn't matter]	any valid actuator in another object, this object rotates vertically
# Object Properties: (type, name, value)
# 	Timer	now         0.00
# 	Float	ago         -1.00
# 	Float	sx          0.00
# 	Float	sz          0.00
# 	Float	cx          1.00
# 	Float	cz          1.00
# 	Int  	mousedown   0
# 	Int  	mousex      0
# 	Int     mousey      0
#
# constants
xsensitivity = -0.10
ysensitivity = 0.10

import GameLogic
import Rasterizer
from math import sin, cos

midx = Rasterizer.getWindowWidth()/2
midy = Rasterizer.getWindowHeight()/2

c = GameLogic.getCurrentController()
m_move = c.getSensor("m_move")
#m_button = c.getSensor("m_button")
o = c.getOwner()

o2 = c.getActuators()[0].getOwner()
# the second object???!!!

# move the cursor back to the center
Rasterizer.setMousePosition(midx, midy)

c = GameLogic.getCurrentController()
mouse = c.getSensors()[0] # change to specify name of sensor if you connect multiple sensors to this script
o = c.getOwner()

# initilization
if o.ago < 0.0:
	Rasterizer.showMouse(0) # hide the cursor
	Rasterizer.setMousePosition(Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)
	deltax = 0
	deltay = 0
else:
	deltax = midx - mouse.getXPosition()
	deltay = midy - mouse.getYPosition()

# based on the cursor's movement, and the constraints, rotate this object
# (and how much time passed)

dt = o.now - o.ago # dt = time passed to this frame
o.ago = o.now

# create copies of the values, then calculate the new ones
## z axis rotation (no constraints)
osz = o.sz
ocz = o.cz
zrot = (3.141592654 * xsensitivity) * dt* deltax
szrot = sin(zrot)
czrot = cos(zrot)
o.cz = -osz*szrot + ocz*czrot
o.sz =  osz*czrot + ocz*szrot

# x axis rotation (there are constraints)
osx = o.sx
ocx = o.cx
xrot = (3.141592654 * ysensitivity) * dt* deltay
sxrot = sin(xrot)
cxrot = cos(xrot)
o.cx = -osx*sxrot + ocx*cxrot
o.sx =  osx*cxrot + ocx*sxrot

if o.cx < 0.0: # prevent looking past top or bottom
	o.cx = ocx
	o.sx = osx


#o.setOrientation([ \
#	[  o.cz, o.sz*o.cx, o.sz*o.sx ], \
#	[ -o.sz, o.cz*o.cx, o.cz*o.sx ], \
#	[    0,     -o.sx,    o.cx   ] ] )

# only horizontal rotation, around z axis
o.setOrientation([ \
	[ o.cz, o.sz, 0], \
	[ -o.sz, o.cz, 0], \
	[  0, 0, 1] ] )

# only vertical rotation [around x axis]
# this is for an empty: [+y axis is forward]
#o2.setOrientation([ \
#	[1, 0, 0], \
#	[0, o.cx, o.sx], \
#	[0, -o.sx, o.cx] ] )
# this is for a camera [-z axis forward]
o2.setOrientation([ \
	[1, 0, 0], \
	[0, -o.sx, -o.cx], \
	[0, o.cx, -o.sx] ] )

that is a two object setup

so, essentially it can put the feet below the camera

# public domain, authored by z3r0_d
# rotate the linking object depending on how the mouse moved
# also, constraints for rotation around on x axis (can limit how far can look up/down)
#
# setup:
# link to mouse movement sensor
# give object these properties:
#  Timer: now =  0.0
#  Float: ago = -1.0
#  Float: sx  =  0.0
#  Float: sz  =  0.0
#  Float: cx  =  1.0
#  Float: cz  =  1.0
#
#### NOTE ####
# the rotation is based on global axes, so this is not suitable
# directly for a camera, it could be modified for one though, 
# probably involving only changes to the last 4 lines (o.setorentation...)

import GameLogic
import Rasterizer
from math import sin, cos

midx = Rasterizer.getWindowWidth()/2
midy = Rasterizer.getWindowHeight()/2

# move the cursor back to the center
Rasterizer.setMousePosition(midx, midy)

c = GameLogic.getCurrentController()
mouse = c.getSensors()[0] # change to specify name of sensor if you connect multiple sensors to this script
o = c.getOwner()

# initilization
if o.ago < 0.0:
	Rasterizer.showMouse(0) # hide the cursor
	Rasterizer.setMousePosition(Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)
	deltax = 0
	deltay = 0
else:
	deltax = midx - mouse.getXPosition()
	deltay = midy - mouse.getYPosition()

# based on the cursor's movement, and the constraints, rotate this object
# (and how much time passed)

dt = o.now - o.ago # dt = time passed to this frame
o.ago = o.now

#o.setOrientation([ \
#	[1.0, 0.0, 0.0], \
#	[0.0, 1.0, 0.0], \
#	[0.0, 0.0, 1.0] ])

# create copies of the values, then calculate the new ones
## z axis rotation (no constraints)
osz = o.sz
ocz = o.cz
zrot = (3.141592654 * -0.10) * dt* deltax # adjust non-pi constant for sensitivity
szrot = sin(zrot)
czrot = cos(zrot)
o.cz = -osz*szrot + ocz*czrot
o.sz =  osz*czrot + ocz*szrot

# x axis rotation (there are constraints)
osx = o.sx
ocx = o.cx
xrot = (3.141592654 * -0.10) * dt* deltay # adjust non-pi constant for sensitivity
sxrot = sin(xrot)
cxrot = cos(xrot)
o.cx = -osx*sxrot + ocx*cxrot
o.sx =  osx*cxrot + ocx*sxrot

if o.cx < 0.0: # prevent looking past top or bottom
	o.cx = ocx
	o.sx = osx

o.setOrientation([ \
	[  o.cz, o.sz*o.cx, o.sz*o.sx ], \
	[ -o.sz, o.cz*o.cx, o.cz*o.sx ], \
	[    0,     -o.sx,    o.cx   ] ] )

this script is somewhat older, and is from mousescript_z3r0_d.blend

well is there a tut?
or could u tell me how?

Well, a while ago there was someone who wrote a tutorial on the 1st camera script, but there was something that didn’t work, so afther doing the tutorial, the script still didn’t work.
Anyways I was thinking to do a tutorial of it, but that will be about some months, so if sonmeone feels something to do it now, that would be great.

here is a really good example of a mouse script for fps games

http://members.lycos.co.uk/legeis/downloads/FPSExample.zip
or
http://members.lycos.co.uk/legeis/modules/mydownloads/