Is there a way to limit the position of the mouse? I want it to only move within a certain area on the y axis, and not move at all on the x axis.
How would you make a machine gun type thing? I know you could use rays, but how would I do it so that it sends out one ray every frame in a random direction? ( but still towards the crosshair)
Have an empty with an IPO rotation around X (a limited rotation).
Parent to the empty another empty with an IPO rotation around Z (a limited rotation as well).
Parent the ray emitter to this empty.
Both rotation emptys get an IPO actuator in property mode.
Let each property set by a random actuator.
The “pattern” depends on the granularity of your random values. Make sure there are no random values outside your IPO curves (see the extended modes in IPO editor)
######################################################
#
# MouseLook.py Blender 2.45
#
# Clark R Thames
# Released under Creative Commons Attribution License
#
# Tutorial for using MouseLook.py can be found at
#
# www.tutorialsforblender3D.com
#
######################################################
########################### Logic Bricks, the only thing you have to set
# Get controller
controller = GameLogic.getCurrentController()
# Get sensor named Mouse
mouse = controller.getSensor("Mouse") #make a mouse: movement sensor and name it "Mouse"
# Get the actuators
rotLeftRight = controller.getActuator("LookLeftRight") #name this actuator "LookLeftRight"
rotUpDown = controller.getActuator("LookUpDown") #name this actuator "LookUpDown"
#connect the Mouse sensor to the Python controller using this code
#and connect that to the two actuators. this can be used on a Camera by itself
#or LookLeftRight on one logic brick on a character, and LookUpDown on the camera.
############################## Need the size of the game window
import Rasterizer
width = Rasterizer.getWindowWidth()
height = Rasterizer.getWindowHeight()
############################### Get the mouse movement
def mouseMove():
# distance moved from screen center
x = width/2 - mouse.getXPosition()
y = height/2 - mouse.getYPosition()
# intialize mouse so it doesn't jerk first time
if hasattr(GameLogic, 'init') == False:
x = 0
y = 0
GameLogic.init = True
return (x, y)
pos = mouseMove()
######## Figure out how much to rotate camera and player ########
# Mouse sensitivity
sensitivity = 0.0020
# Amount, direction and sensitivity
leftRight = pos[0] * sensitivity
upDown = pos[1] * sensitivity
# invert upDown
upDown = upDown
######### Use actuators to rotate camera and player #############
# Set the rotation values
rotLeftRight.setDRot( 0.0, 0.0, leftRight, False)
rotUpDown.setDRot( upDown, 0.0, 0.0, True)
# Use them
GameLogic.addActiveActuator(rotLeftRight, True)
GameLogic.addActiveActuator(rotUpDown, True)
############# Center mouse pointer in game window ###############
# Center mouse in game window
Rasterizer.setMousePosition(width/2, height/2)
Ok but I’m not trying to get mouselook. I’m trying to limit the position of the cursor on the screen. I want it to not move at all on the x axis, and only move a certain distance on the y axis.
Basically, I have an object that is set where a ray from the mouse hits, and I don’t want that object to hit the top or bottom of the screen. I want to limit it to the center third or so.
Ok there we go. I got it now. So how is the screen measured? Like, what would I put in for the numbers for the far right, bottom etc. Or does it just go by screen resolution?