Mouse movement sensors

Hi all,

Have been scouring every bit of information I can find on mouse movements…

I just want a mouse sensor that works like the keyboard or joystick sensor for the mouse…

After much serchingI came across this script snipplett

 # To use a mouse movement sensor "Mouse" and a 
       # motion actuator to mouse look:
       import Rasterizer
       import GameLogic

       # SCALE sets the speed of motion
       SCALE=[1, 0.5]
       
       co = GameLogic.getCurrentController()
       obj = co.getOwner()
       mouse = co.getSensor("Mouse")
       lmotion = co.getActuator("LMove")
       wmotion = co.getActuator("WMove")
       
       # Transform the mouse coordinates to see how far the mouse has moved.
       def mousePos():
               x = (Rasterizer.getWindowWidth()/2 - mouse.getXPosition())*SCALE[0]
               y = (Rasterizer.getWindowHeight()/2 - mouse.getYPosition())*SCALE[1]
               return (x, y)
       
       pos = mousePos()
       
       # Set the amount of motion: X is applied in world coordinates...
       lmotion.setTorque(0.0, 0.0, pos[0], False)
       # ...Y is applied in local coordinates
       wmotion.setTorque(-pos[1], 0.0, 0.0, True)
       
       # Activate both actuators
       GameLogic.addActiveActuator(lmotion, True)
       GameLogic.addActiveActuator(wmotion, True)
       
       # Centre the mouse
       Rasterizer.setMousePosition(Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)

Well I have this working with a cube,a mouse sensor>movement , and a motion sensor with some force…

when I run the game, and move the mouse the force is applied to the cube as expected…

I just cant figure out how to make it a sensor for RIght mouse movement, left mouse movement, and up and down movement…

TIA for any help :slight_smile:

do you want to move the cube like a cursor with the mouse?

I just want so when I move my mouse to the left it triggers an actuator… another script sensor for move right, up, down Etc…

somewhat like the keyboard and joystick sensors, only for the mouse…

p00f: I just started fooling with mouse movement last night, but here’s what I would suggest:

Give your object four properties of type “int”. Name them oldX, oldY, newX, and newY. I think that 0,0 is the top left corner of the screen, so my “up down left and right” in the script are based off that assumption.


import GameLogic as g

cont = g.getCurrentController()
own = cont.getOwner()
mouseMov = cont.getSensor("<i>your mouse movement sensor</i>")

### <i>Find the new mouse coordinates</i>
own.newX = mouseMov.getXPosition()
own.newY = mouseMov.getYPosition()

### <i>Compare to the old coordinates (stored in oldX and oldY)</i>
if own.newX &gt; own.oldX:
     <i>The mouse moved right.  Do what you want to do.</i>
elif own.newX &lt; own.oldX:
     <i>The mouse moved left.  Do what you want to do.</i> 

if own.newY &gt; own.oldY:
     <i>The mouse moved down.  Do what you want to do.</i>
elif own.newY &lt; own.oldY:
     <i>The mouse moved up.  Do what you want to do.</i>

### <i>Store the new coordinates as the old ones 
</i>###<i> for the next time through.</i>
own.oldX = own.newX
own.oldY = own.newY

WOW!

thanks blendzo!!

Going to give this a try now :slight_smile:

And If you need to rotate “X” and “Z” axis??? please help!!!