please save my time… ive spend wasted my time search for this. is it exist? or not? do i have to go back rebuild on 2.49 ? because its working all fine. but i like 2.5 better. (iam going make huge map… will need 2.5 alpha which 2.49 dont has.)
Well, I made one script like this to 2.5x. Its very simple and works pretty well… It’s not commented but I think it’s not very difficult to understand the code.
import bge
#bge.render.showMouse(True)
cont = bge.logic.getCurrentController()
obj = cont.owner
mouse = cont.sensors['Mouse']
def DeltaMouse(Xcenter,Ycenter,lockToCenter=False,Xpos=mouse.position[0],Ypos=mouse.position[1]):#this function calculates the ditance (in pixels) of the mouse from two given points
Dx = Xpos - Xcenter
Dy = Ypos - Ycenter
delta = [Dx,Dy]
if lockToCenter and Dx or Dy:
bge.render.setMousePosition(Xcenter,Ycenter)
return delta
delta = DeltaMouse(int(bge.render.getWindowWidth()/2),int(bge.render.getWindowHeight()/2),True)
if obj['firstTime']:
delta = [0,0]
obj['firstTime'] = False
Hrot = delta[0] * obj['sens'] / -1000
Vrot = delta[1] * obj['sens'] / -1000
if obj['x']: obj.applyRotation([0,0,Hrot])
if obj['y']: obj.applyRotation([Vrot,0,0],True)
To work the scrip needs a set up like this:
Important:
-The logic bricks and properties have to be set to the camera
-The mouse sensor HAVE TO be called “Mouse” and don’t forget to change the “Mouse Event” to “Movement”
The properties:
“firstTime” - Have to be boolean and True. (Avoids a gap in the first movement of the camera)
“x” - Have to be boolean and allows or not the x axis movement
“y” - Same as “x” but for the y axis
“sens” - Can be float or integer controls the sensitivity of the movement (bigger means more sensitive)
-The names ARE case sensitive so they have to be written like in the image the and you have to set all this properties to the script work.
I think there was a problem with mouse controls in the official 2.5 alpha release. You need to use a recent SVN build or wait for the upcoming 2.5x beta release. Recent SVN builds can be found at www.graphicall.org
@supermoaaa
Yeah sure, feel free to use as you want
@s0l1dcra5h
You didn’t set the prps to “True”. The “firstTime” prop have to be true and to move the camera “x” and/or “y” have to be “True”. And the “sens” prop should be bigger than 0. (negative values will produce inverted axis movement)
I’ll make a .blend example with commented code and post here later…
[edit]
I’ve just tested in Alpha 2.52.0 and it doesn’t work, but in 2.52.5 (from GraphicAll.org) works nicely…
If the mouse looks like its drifting I think it’s because more recent builds return the mouse position as a normalised value, you need to multiply the mouse position by the window width and window height.
Yeah, this is the problem, maybe I write another version to work with 2.52.0. For now I’ve made a example file, I’m just waiting to be released in Blendswap.com than I post the link here…