"looking" at mouse position

Hey there, this is my first thread on this very wide forum. Incase you havent guessed by the last sentece…im fairly new to blender.
I have spent many a sleepless night trying to work out how to make an object “look” (by the way of rotation) at the mouse position.
Ideally, I am after the effect that as the mouse moves around, the object is anchored, yet rotates to face the mouse pointer where ever it goes on the screen. Ive seen it in Panda3D, but then I discovered Blender…much move fun to play with!
Can someone out there give me a bit of insight on how to make this happen without the assumption that I know everything in this vast program?
thanx in advance

You must use some Python scripting to do this. It cannot be done with Logic Bricks alone, because the Logic Bricks do not have access to the mouse coordinates.

The simple steps to accomplish this:

  1. Make an object of some sort follow the mouse movement, like a mouse cursor (this is the part that takes Python scripting).
  2. Cause the object you want to look at the mouse position to track to the cursor object.

Read my tutorial on custom cursors to learn how to do step 1. http://www.blendenzo.com/tutCustomCursors.html

For step 2, select the cursor object you have made and press the “N” key over the 3D viewport to see the Transform Properties window. Read the object name in the field named “OB:”. Now select the object you want to look at the cursor and go to the Logic Panel in the buttons window. Add an Always sensor and turn off the button labeled “TRUE Level Triggering (Pulse Mode)”. This will cause the Always sensor to fire only once when the game starts and never again. The tracking actuator is “sticky” so it only needs to be triggered once. It is a waste of resources to let it keep triggering over and over again. Add an AND controller and add an Edit Object actuator. Connect all of the bricks, then set the Edit Object actuator to “Track To”. In the “OB:” field that appears, type the name of the cursor object that you found earlier. Click the button labeled “3D” if you want the object to track on all axes.

Special requirements:
My cursor tutorial teaches you to use an overlay scene for the cursor, but you will not be able to do that in this case. The cursor must be in the same scene as the object that is tracking it, because an object cannot track something in another scene.

If you do not want the mouse cursor to appear on screen, then you can use an Empty or an object set to “Invisible”.

Let me know if you have any trouble understanding these instructions. I can add pictures if you need them (please try it without the pictures first, though… pictures take a lot of time).

thanx man, i actually browsed thru your tutorial in searching…and figured something like this would be the way…will try now and let ya know…FYI, i am hoping to have the cursor invisible

works great!
is there some way of causing the rotating object to "rotate slightly more?
all the same, it has solved my nightmare…thanx so much!

I’m glad you got it working. I’m not sure what you mean by “rotate slightly more” though. Do you mean you want to make it a smoother rotation instead of such a sharp transition?

If that is what you meant, there are a couple of ways to do that. I think that the “Time” field on the Edit Object >> Track To actuator is supposed to handle that. Try changing that value a bit. If it doesn’t give you the result you’re hoping for, I can explain another method that will actually set up a rotation animation during the game depending on how quickly you move the mouse.

I know that this post is old but I just stumbled across it and it was just what I needed.
Thank you, Thank you, Thank You Blendenzo!!! You saved me a ton of time, but… of course there is a slight problem. The mouse is super sensitive. Moving it from one end of the screen to the other makes the camera move like a 4 year old with A.D.D. after he just downed a 6 pack of red bull. Any idea about how to slow the camera movement down to a manageable speed?

Thanks,

Thanks man, now I can go on with my 2D-shooter!