A mouse question


(Pooba) #1

Hey everyone,

I was just wondering, I finally got a mouse script and i got it to work! Now i want to have the option to invert the mouse, is there a way to do this with my script?

thanx

Pooba


(muteinvert) #2

well, thats easy

find all the z x and y properties for the mouse, and in front of the number, put a -, or if there already is a -, remove it.


(theeth) #3

It might be a little more subtile than this actually. You probably use dX and dY variables in you script (variation in X and Y axis). If so, I think multipling them by -1 should do the trick. No sure though.

Martin


(Pooba) #4

I can’t really find it, here’s my script:

from GameLogic import *
from Rasterizer import *

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

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

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

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

if (Xpos > Width):
    XDiff = Xpos - Width
    RightMove.SetDRot(0, (XDiff /Own.move),0,1)
    addActiveActuator(RightMove,1)

if (Xpos > Width):
    XDiff = Xpos - Width
    LeftMove.SetDRot(0, (XDiff /Own.move),0,1)
    addActiveActuator(LeftMove,1)

if (Ypos < Height):
    YDiff = Ypos - Height
    UpMove.SetDRot(0, (XDiff /Own.move),0,0,1)
    addActiveActuator(UpMove,1)

if (Ypos < Height):
    YDiff = Ypos - Height
    DownMove.SetDRot(0, (XDiff /Own.move),0,0,1)
    addActiveActuator(DownMove,1)

addActiveActuator(LeftMove,0)
addActiveActuator(DownMove,0)
addActiveActuator(RightMove,0)
addActiveActuator(UpMove,0)

setMousePosition(Width,Height)

What do I change? Should I use a different mouse script?


(saluk) #5

Hmm, try this. Not sure if it will be right though. And it appears the code is buggy anyway, because it uses XDiff for the y movement when it should be YDiff.


if (Ypos < Height):
    YDiff = Ypos - Height
    UpMove.SetDRot(0, (<b>XDiff[b] /Own.move),0,0,1)
    addActiveActuator(UpMove,1)

Change this:


    UpMove.SetDRot(0, (XDiff /Own.move),0,0,1)

to this:


    UpMove.SetDRot(0, [b]-(Y</b>Diff /Own.move),0,0,1)

And do the same here:


    DownMove.SetDRot(0, (XDiff /Own.move),0,0,1)
#Changes to
    DownMove.SetDRot(0, <b>-(Y</b>Diff /Own.move),0,0,1)


(Pooba) #6

Thanx Saluk, that inverted it!

Also, I noticed that your FPS (Soldier Down) doesn’t allow the camera to keep turning up and down, once you get to look at your character’s feet it won’t turn any more down. How’d you do that?

Thanx

Pooba


(saluk) #7

I used a cube in front of the player, a cube behind the player, and a sensor cube above the players head, to stop movement too far above and below. There are 2 collision sensors on the head cube which are attached to the mlouse script. One of them looks for collision with the cube in front, the other sensor looks for collision with the cube in rear. Lets call them “frontcol” and “rearcol”. Oh yeah, since you probably are doing just an fps (there’s no player model) you can put the sensor cube a unit or so directly above the camera.
Anyway, I aligned the cubes so that when the camera rotates down the sensor cube will eventually collide with the front cube, and rotation too far the other direction will cause a collision with the rear cube. Now this isn’t quite enough to stop the rotation. In the mouse script, you have to add the collsion sensors:
frontcol = c.getSensor(“frontcol”)
rearcol = c.getSensor(“rearcol”)

and check if they are true before you allow the mouse script to look up or down:


if (Ypos &lt; Height) and frontcoll.isPositive == 0:
    YDiff = Ypos - Height
    DownMove.SetDRot(0, (XDiff /Own.move),0,0,1)
    addActiveActuator(DownMove,1) 

etc for looking up

Edit: Man! Sooo many spelling errors


(Pooba) #8

Couldn’t I just invert the collisions and make it so that the python script would only initialize when the cubes weren’t colliding with something?

Pooba


(saluk) #9

If the script only initialized when no collisions were registered, as soon as you look too far you would lose mosue supposrt entirely. You only want to block access within the script to that direction.


(Peter) #10

Here´s what I use in my game and is a better way than using a lot of sensors (i think…):
On the camera (or empty that the camera is attached to) I have a motion actuator. In the mousecript I check the Z-axis(up/down in my case) and make shore that it´s not rotating more than a sertain degree.

First, i get the z-rotation from the Camera:


camera_motion = Controller.getActuator("camera_actuator")
camera_owner = camera_motion.getOwner()
camera_rotation_matrix = camera_owner.getOrientation()

camera_z_rotation = camera_rotation_matrix[2]

Then, I use that info to limit the rotations:


if (Ypos &lt;= Height):
    YDiff = Ypos- Height 
    if(camera_z_rotation[2] &gt; -0.9):
       camera_motion.setDRot((YDiff/Own.move),0,0,1)
       GameLogic.addActiveActuator(camera_motion,1)

elif (Ypos &gt; Height):
    YDiff = Ypos- Height 
    if(camera_z_rotation[2] &lt; 0.9):
       camera_motion.setDRot((YDiff/Own.move),0,0,1)
       GameLogic.addActiveActuator(camera_motion,1)

Hope that helps / Peter


(saluk) #11

It’s much better Peter, thank you. Silly math, I can’t do math :frowning:

It’s nice to know others can.