Controlling an objects IPO frames with mouse

Hello, I am trying to get my player rig complete.

I have an object with IPO rotation recorded. I am trying to control it with the objects properties.

I have this script that is supposed to ramp the mouse movements of the X and Y coordinates to the objects x and y properties.

For some reason the script does not seem to be changing the properties .

import Rasterizer 
 
co=GameLogic.getCurrentController() 
ob=co.getOwner() 
s1=co.getSensor("mouse") 
 
x=s1.getXPosition() 
y=s1.getYPosition() 
if x>32000: 
   x=0 
if y>32000: 
   y=0 
 
ob.x=x*100/Rasterizer.getWindowWidth() 
ob.y=y*100/Rasterizer.getWindowHeight()

It is to control the top of my player’s rotation. (sort of like a tank turret)

When I move the mose on the X axis i want it to change an integer property called X, when i move Y i want it to add or subtract from the Y property. That way I can control the IPO frames with the action actuator.

Thanks for any help!

I think it’s just a case of needing to reassign the value back to the game object property, eg:

x = own['x']

ipoX = /mouse position x or whatever

own['x'] = ipoX

I thinks :slight_smile:

Thanks, did not seem to help though.

That code is all wrong , lol … If you are trying to get that to work in Blender 2.5+ you need to import bge and the default name of the mouse sensor is Mouse not mouse … Caps need to match exactly … I’m not even good at scripting but i can tell it won’t work like that in Blender 2.65. Try something like this:

import bge

controller = bge.logic.getCurrentController()
object = controller.owner
sensor1 = controller.sensors[‘Mouse’]

x = sensor1.position[0]
y = sensor1.position[1]

notice how mouse sensor gives you a normalized list of [x,y] and that means that the values go between 0 and 1 , so 0.5 means center of the screen … that also means that the next part of the code is checking for the wrong range of values … x and y will never reach values of 32000 , lol … the next part of code after that is all wrong again, because of 3 different reasons … your object has no property called x anywhere unless you create one and the call to get window width and height is:

bge.render.getWindowWidth()
bge.render.getWindowHeight()

This one is not using any ipo or animation clips

Attachments

MouseRotation.blend (73.8 KB)

Thanks blenderer!