Game Development Community

Mouselook headaches

by Jared Chavez · in Torque Game Engine · 05/05/2008 (4:14 pm) · 5 replies

Ugh... first time I've had to post here since I started messing with TGE 1.5.2.

I'm sure there must be something simple I'm doing wrong but I've been looping in circles all day for this seemingly easy task :)

So... I'm trying to link Mouselook to the right mouse button in my game so that you only look around when the right mouse button is held down. I am having a helluva time getting this to work correctly. I did see the WoW Player Controls resource but this uses script callbacks to make you move when you have the right mouse button held down. I had wanted to avoid this but havent been able to come up with a totally engine driven solution. The other mouselook resources I found all bind mouselook to a keyboard event. Can someone help me?

What I've tried so far was to enable the cursor on the PlayGUI and then wrote onRightMouseDown and onRightMouseUp functions for gameTSCtrl. I've tried several iterations of what to do in these functions but the problem boils down to 2 scenarios...

1. Using canvas->showCursor() true and false I can get the cursor to toggle on and off depending on the state of the right mouse button but the player cannot mouselook when the button is down. This is expected as it seems that this simply turns mouse cursor rendering on or off.
2. Using canvas->setCursorOn() true and false works to turn off the cursor and enable movment when the right mouse button is pressed, but releasing the mouse button doesn't re-enable the cursor... as the control no longer recognizes the mouse input event since the cursor is off, I guess? How do I avoid this?

What I'm not comprehending is how the engine handles movement. It seems like it is checking to see if Cursor is ON and, if so, doesnt worry about moving the camera but I can't find where in the code this is done to have it check something else... like say a player variable or something... Then I could use method #1 to set that variable and be on my way. :)

About the author

Recent Threads


#1
05/13/2008 (7:55 pm)
*1st and only bump*

No one have any insight on this? :(
Have tinkered with WoW control but peformance is heavily degraded. Would still like to accomplish this fully in the engine code.
#2
05/14/2008 (11:36 am)
Mouselook is handled by a scriptmethod which is bound to an actionmap. This method modifies the $mvMove vars to perform the movement.

If the cursor is on in the gui, the gui will handle ( and consume ) all mouse input before it reaches the actionmap.

Does that help any?
#3
05/15/2008 (1:24 pm)
Thank you James, after reading your explanation it became clear that the WoW controls resource was doing things correctly. I was able to find and isolate the perfomance issues that it introduced into my build and fix em :)
#4
05/15/2008 (1:30 pm)
You might want to post your resolution here or in a resource, I know I've seen many people inquiring about the same issues and looking to do the same thing.
#5
05/17/2008 (8:08 am)
Sure... I don't know how to submit a resource but I'll post this on the resource page too. My problem was due to the way the WoW player controls resource was trying to keep track of cursor position, record a mousedrag, then move the mouse back to its original position and skip the next mouse move. This caused big performance problems on systems without beefy graphics cards for some reason. I'm a newb so I'm not really sure why. My solution was to change the last few lines of GameTSCtrl::onMouseDragged from...
Canvas->ignoreNextMove = true;
Canvas->setCursorPos( lastCursor);
to...
lastCursor = evt.mousePoint - diff;		
Canvas->setCursorPos(lastCursor);
Getting rid of the skip next mouse move function call and using the captured evt mousepoint when calling setPosition() on the cursor made things run smooth as silk for me without having the issue of the mouse ceasing to work once you scroll it off the screen. Note, though, that this resets mouse position to the center of the screen rather than putting it back where you first initiated your drag. This was actually what I wanted in my game anyway, so :)