Hi,
I just made a little script that makes a 2d cursor follow the mouse. This may be useful for menus and such stuff… I’m sure that there are already tons of scripts such as this one, but I was tired of searching in this forum, because most of the links don’t work any more. And doing that was a good exercise.
And here are the scripts contained in this file:
# mouse_init.py - This script initializes the cursor settings for the mouse_move.py script.
#
# Copyright 2004 Gabriel Walt
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# To make this script work, you have to create the following structure in Blender 2.25:
# Add the following logic bricks to the object that will be your cursor:
# Always [without pulsing] => Python [call this script].
import Rasterizer
Rasterizer.showMouse(0)
Rasterizer.setMousePosition(Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)
# mouse_move.py - A little script that makes an object follow the mouse, as for a cursor.
#
# Copyright 2004 Gabriel Walt
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# To make this script work, you have to create the following structure in Blender 2.25:
# Create an object that will be your cursor and add the following logic bricks:
# Mouse [Movement] called "mouse" => Python [call this script] => Motion called "move".
# These parameters may be modified to suit your needs.
# The sensibility is the speed of the mouse, that must be adjusted depending the scale.
# And the x/y parameters define a square in which the cursor movement will be limited.
sensibility = 0.05
xMax = 8
xMin = -8
yMax = 8
yMin = -8
import GameLogic
import Rasterizer
cursorC = GameLogic.getCurrentController()
cursor = cursorC.getOwner()
cursorS = cursorC.getSensor("mouse")
cursorA = cursorC.getActuator("move")
cursorPos = cursor.getPosition()
xPos = cursorS.getXPosition()
yPos = cursorS.getYPosition()
xMid = Rasterizer.getWindowWidth()/2
yMid = Rasterizer.getWindowHeight()/2
if (cursorPos[0]+(xPos-xMid)*sensibility < xMin):
xPos = xMid+(xMin-cursorPos[0])/sensibility
if (cursorPos[0]+(xPos-xMid)*sensibility > xMax):
xPos = xMid+(xMax-cursorPos[0])/sensibility
if (cursorPos[1]+(yMid-yPos)*sensibility < yMin):
yPos = yMid+(cursorPos[1]-yMin)/sensibility
if (cursorPos[1]+(yMid-yPos)*sensibility > yMax):
yPos = yMid+(cursorPos[1]-yMax)/sensibility
cursorA.setDLoc((xPos-xMid)*sensibility, (yMid-yPos)*sensibility, 0, 0)
GameLogic.addActiveActuator(cursorA, 1)
Rasterizer.setMousePosition(xMid, yMid)
Have fun!
Gabriel