mouse script, please help

(ineedanewbi) #1

can someone help me make a good mouse scrip for a first person shooter

i want one that limits the motion so that i cant look over 90 degrees up or down

thanks for volenteering

(wiseman303) #2

(cluh) #3

i use ipo for the y rotating, mine uses two scripts

(Ben) #4

-This is the Quakemousetest script modified.You must have the Camera
rotation up or down in xX direction:

from GameLogic import *
from Rasterizer import *
from math import *

Cont = getCurrentController()
Own = Cont.getOwner()
Sens = Cont.getSensors()
Sensor = Sens[0]
######## Matrix2Euler ########
mat = Own.getOrientation()
size = [1,1,1]
def mat2euler(mat, size):
scale = [0.0, 0.0, 0.0]
if size[0]!=0.0:
scale[0] = 1.0/size[0]
if size[1]!=0.0:
scale[1] = 1.0/size[1]
if size[2]!=0.0:
scale[2] = 1.0/size[2]
angle_y = -asin(mat[0][2] * scale[0])
C = cos(angle_y)
if abs(angle_y)>1.0e-10:
C = 1.0/C
angle_x = atan2((mat[1][2] * scale[1]) * C, (mat[2][2] * scale[2]) * C)
angle_z = atan2((mat[0][1] * scale[0]) * C, (mat[0][0] * scale[0]) * C)
angle_x = 0.0
angle_z = -atan2((mat[1][0] * scale[1]), (mat[1][1] * scale[1]))
return (angle_x, angle_y, angle_z)

rot = mat2euler(mat,size)
rot_x = rot[0]

Height = getWindowHeight()/2
Width = getWindowWidth()/2

get current mouse position

Xpos = Sensor.getXPosition()
Ypos = Sensor.getYPosition()

get actuators

RightMove = Cont.getActuator(“Right”)
LeftMove = Cont.getActuator(“Left”)
UpMove = Cont.getActuator(“Up”)
DownMove = Cont.getActuator(“Down”)

check positions relative to old position

Mouse going right

if (Xpos > Width):

Move right

XDiff = Xpos - Width
RightMove.setDRot(0,(XDiff /Own.move),0,1)

Mouse going left

if (Xpos < Width):

Move left

XDiff = Xpos - Width

Mouse going up

if (Ypos < Height):

Move up

YDiff = Ypos - Height
if rot_x < -2.7 :
YDiff = 0

Mouse going down

if (Ypos > Height):

Move down

YDiff = Ypos - Height
if rot_x > 0:
YDiff = 0

Shut off all actuator movements


Set the mouse to the center of the game screen


and of course the bricks set as the script tells.If you have probs give me an e-mail and I’ll send the blend file.

(saluk) #5

You didnt put anything in there to represent tabs…

(Ben) #6

when I quote it loses all tabs.But I think it can be simple to put in the line below def,if and for, a tab space.

(ineedanewbi) #7

thanks everyone

i tried to use the modified quakemousettest but it didnt work

can someone show me how to use it, or make an example file with the bricklogic in?