rotate by position of mouse??

ok I was searching and couldn’t find so I am, gonna ask. is there any way to make an object rotate with the mouse. otherwise make the object keep facing the mouse.
oh.:: and just to ask a Q real fast how do I make the mouse cursor visible–(haven’ t searched for this tough).

Heres a script to show the mouse.

import Rasterizer
Rasterizer.showMouse(1)

I don’t know how you would rotate an object with the mouse tho.

“import Rasterizer
Rasterizer.showMouse(1)” dosent work for me is there another way to show the mouse cursor?

k thanks ima try that later,
hope I could get the rotation though.:o

What is this for, a cannon or something?

You’ll need a script that reads the mouse coordinates from the Rasterizer and runs an IPO on your object.

First set up the IPO curve on your object. Make frame 1 one extreme and a high frame (say 101 for instance) the opposite extreme. Then set up the logic:

Mouse (Movement) >> Python >> IPO (Property)

Write this code for the Python controller:

import Rasterizer

cont = GameLogic.getCurrentController()
own = cont.getOwner()
mouse = cont.getSensor("<i>your mouse sensor name goes here</i>")
followMouse = cont.getActuator("<i>your IPO actuator name goes here</i>")
animLength = 100   ### <i>This is how long the IPO is</i>
winWidth = Rasterizer.getWindowWidth()
xRatio = winWidth/animLength  ### <i>How many pixels wide per frame
</i>
### <i>To find the right frame in your IPO, divide the current mouse 
</i>### <i>position by the ratio value.  Add 1, since your end frames are
</i>### <i>1 and 101, not 0 and 100</i>
frame = (mouse.getXPosition()/xRatio) + 1

### <i>Now run the IPO actuator to animate to the right frame.  The
</i>### <i>value of "1" means "True" or "Turn it on."  0 is false/turn off.</i>
GameLogic.addActiveActuator(followMouse, 1)

To rotate on two axes, you will need to split the rotation between two objects. One of them can be your cannon or whatever, and the other can be an empty. Make the empty the parent of the object, then give it an IPO on the opposite axis and the same logic and code, except change it to contain the word “Height” where the above code says “Width” and “Y” where it says “X”.

Hope that helps.

Here’s a little demo I made. Hope it helps.

http://clonedad.netfast.org/CustomCursors.blend

oh it is a to down shoter. like um that game for snes, can’t remember the name but it is that one with the coop in it.
thanks guys works fine, I had to fiddle with the codes abit (at least I know a little c++ to figure out python) but I got it working.:slight_smile: