Mouse view...

(xintoc) #1

Ok, I don’t understand how to set this right. I don’t know how
to move camera with mouse movement, I have this python,
but I don’t know how to use it. I have tried almost everything
to apply it, but when I move the mouse then nothing happens.

from GameLogic import *
from Rasterizer import *

Cont = getCurrentController()
Own = Cont.getOwner()
Sens = Cont.getSensors()
Sensor = Sens[0]

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

get current mouse position

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

get actuators

RightMove = Cont.getActuator(“Rechts”)
LeftMove = Cont.getActuator(“Links”)
UpMove = Cont.getActuator(“Auf”)
DownMove = Cont.getActuator(“Ab”)

check positions relative to old position

Mouse going right

if (Xpos > Width):
# Move right
XDiff = Xpos - Width
RightMove.setDRot(0,0,(XDiff /Own.move),1)

Mouse going left

if (Xpos < Width):
# Move left
XDiff = Xpos - Width

Mouse going up

if (Ypos < Height):
# Move up
YDiff = Ypos - Height

Mouse going down

if (Ypos > Height):
# Move down
YDiff = Ypos - Height

Shut off all actuator movements


Set the mouse to the center of the game screen


(gecko) #2

just open this script in the text-window, and dont forget its name, then, in the realtime-buttons of your camera,
add a always-sensor ->
python-controler (where you wirte the name of the script in) ->
the four directions as movements and link them each to the controler. they shuld have the same name like the ones in the script, here they are called “links, rechts, auf, ab”.
then press p and I hope you’ll be happy :smiley:

(Ben) #3

-No,no.This script must be attached in this way:
1)Select your camera
2)add a Mouse Movement Sensor
3)connect it with a Python Controller that handles the script name
4)add two float properties named x and y

P.S.This part is ok

just open this script in the text-window, and dont forget its name, then, in the realtime-buttons of your camera

(ndnchief) #4

Could someone post a working Blend File as an example. For some reason I cant get this script to work? Does the X Diff have to be indented?

Thanks NDNChief, Been away for a while, good to be back! :smiley:

(Ben) #5

-Try this link:

-this is a little mor complicated example.It divides the horizontal move and the vertical move in order to avoid the complete rotation in vertical sense.

(ndnchief) #6

Thanks Ben for the example, for me, it helps to see how the logic bricks are set up also. I was able to duplicate a working file. Thanks again…

The NDN…

(xintoc) #7

Actually the tips you posted here, I knew all them, but the ‘‘POINT’’
was that I wanted how you guys do this, When I did this the camera
rotated wrong a it was so slow when I pressed ‘P’ that it almost crashed.
It was just like the frame rate was very low.