controlling object movement with Mouse

I’m trying to control an object using the mouse. I’ve got a script that gets the mouse position and then sets the dLoc values according to the mouse’s position.
However, it’s not working quite as I want it to. The object doesn’t stop when the mouse stops. And, the further away from the center of the screen (0,0), the faster the object goes.
I just want the object to be exactly where the mouse is all the time. Any ideas? Here is the file:

mouse-obj-movement09.blend

Thanks!

yep, sounds exactly like what you did

if the speed is based on the cursor’s position, only when the cursor is at the origin [I belive it is the lower left corner] will the object not move

stop trying

just make it so that your object moves based on the cursor’s movement, but don’t try to get [or assume that they are] in synch, it will be very difficult [particularly when the edges of the camera don’t align with the edges of the view, like in the 3d view]

so, what I’m trying to say is that you should set the position of your object based on where the cursor is… it seems that is a lot more like what you’re trying to do anyway

ok, I guess to be more precise - I’m looking for any specific help to this issue. I understand that the approach itself may be incorrect, but if I knew the solution, I’d just do it, right?

kay, I wasn’t feeling well before, I’m much more upbeat now

so, I’m confused as to what you’re trying to do

it sounds like you want a blender 3d object to stay perfectly lined up with the system cursor [as it moves around…]? is this correct?

so… does that mean it will be on a plane perpendicular to the screen?

do you have


W = Rasterizer.getScreenWidth()
H = Rasterizer.getScreenHeight()

Rasterizer.setMousePos(W\2,H\2)

at the end?
That Might Work

it sounds like you want a blender 3d object to stay perfectly lined up with the system cursor [as it moves around…]? is this correct?
so… does that mean it will be on a plane perpendicular to the screen?

yep, that’s exactly right. It seems like there is some equation that I need to use. Or, I need to move the object using something other than the dLoc attribute. Maybe I’m mistaken about what the dLoc does. I thought it would put the object at a certain location, not move it continuously (like it’s doing now).

do you have
W = Rasterizer.getScreenWidth()
H = Rasterizer.getScreenHeight()

Rasterizer.setMousePos(W\2,H\2)

well, yes. there is a script at the very beginning that sets the mouse to the center of the screen. But, I want the mouse to move normally and have an object go along with it. Like Pong! The paddle moves exactly where the mouse goes (in real time).

This should do it:

import Rasterizer as r

g = GameLogic
c = g.getCurrentController()
o = c.getOwner()

mMove = c.getSensor("Move")

width = float(r.getWindowWidth())
height = float(r.getWindowHeight())

aspecty = height/12.0
aspectx = width/16.0

o.MouseX = (mMove.getXPosition()-width/2)/aspectx
o.MouseY = -(mMove.getYPosition()-height/2)/aspecty

o.setPosition([o.MouseX,o.MouseY,0])

Brilliant! Thank you very much!
I see I needed to use setPosition instead of setDLoc.

I’ve just posted an example blend in this thread if you want to look at a working file.