Mouse Look with right click
by Richard Preziosi · in Torque Game Engine · 02/14/2007 (4:45 pm) · 15 replies
I have come to the need of the ability to have the cursor available in the game, as well as have it set up where holding down the right mouse button will allow the player to walk around and look at the same time, think EQ/EQ2. I found a thread about this, but the code did not seem to work and seemed a bit old and unfinished. Any info on this, and which exact file I need to concentrate on, I could possibly figure it out myself. Any help will be greatly appreciated, thanks.
#2
02/14/2007 (6:46 pm)
Are those c or c++ files, cause i have no way of opening them, was looking for more of a way to do it with script files. I could be wrong though, thanks.
#3
moveMap.bind( mouse, button1, FreeLook );
//------------------------------------------------------------------------------
function FreeLook(%val)
{
if (%val)
{
echo ("pressed.....");
moveMap.bind(mouse, xaxis, yaw);
moveMap.bind(mouse, yaxis, pitch);
}
else
{
echo ("released...");
moveMap.bind(mouse, xaxis, yaw);
moveMap.bind(mouse, yaxis, pitch);
}
}
Any help would be appreciated, thanks.
02/14/2007 (7:04 pm)
This is the code that I have at the moment, sorry I don't know how to make a scrollable code box, but I have this code in the example/game/client/default.bind;moveMap.bind( mouse, button1, FreeLook );
//------------------------------------------------------------------------------
function FreeLook(%val)
{
if (%val)
{
echo ("pressed.....");
moveMap.bind(mouse, xaxis, yaw);
moveMap.bind(mouse, yaxis, pitch);
}
else
{
echo ("released...");
moveMap.bind(mouse, xaxis, yaw);
moveMap.bind(mouse, yaxis, pitch);
}
}
Any help would be appreciated, thanks.
#4
[*code]
function foo(%bar)
{
$foobar = %bar
}
[*/code]
Just remove the * from each [] box, and anything in between those sections will be in a more readable form.
Your method is kind of inefficient, and could quite possibly cause overhead. If you are using Windows as your OS, go grab Microsoft Visual Studio 2005 express. That will allow you to edit and compile the source code, otherwise, your gonna miss out on a lot of opportunities to add functionality more easily when scripting just can't cut it.
02/14/2007 (7:38 pm)
For putting in code segments use this:[*code]
function foo(%bar)
{
$foobar = %bar
}
[*/code]
Just remove the * from each [] box, and anything in between those sections will be in a more readable form.
Your method is kind of inefficient, and could quite possibly cause overhead. If you are using Windows as your OS, go grab Microsoft Visual Studio 2005 express. That will allow you to edit and compile the source code, otherwise, your gonna miss out on a lot of opportunities to add functionality more easily when scripting just can't cut it.
#5
02/14/2007 (7:44 pm)
I'll check it out, the only reason i was using scripts instead of hard coding it, is basically because i dont' know anything about object oriented programming or any type of programming for that matter, just had some books on torque script, so figured it was the easy way to start out. Thanks though, i'll see about the visual studio though.
#6
02/14/2007 (7:47 pm)
You always have option B, which is to have someone else compile the executable for you and provide you with the changed source code, so that when you do dive into source code you can see what changes were made.
#7
02/14/2007 (8:00 pm)
Well that would then be the question, you seem to be knowledgeable, would you perhaps be willing to edit the source code to where I could right click for a mouse look while in game, seems a simple task, but I really do not know.
#8
The mouse is already bound to yaw & pitch. Your function simply binds those functions again if the right mouse button is pressed and does the exact same thing when it's released.
Maybe you intended to do this:
That will bind yaw & pitch on right mouse button down and unbind yaw & pitch on release (make sure you comment out where yaw & pitch are bound normally inside of default.bind.cs i.e. let the function take care of it).
However that's not the ultimate problem here, the problem is that when the mouse is in focus the engine disables yaw & pitch so you can move the mouse pointer around (instead of the player). The other problem is once the mouse cursor is turned on, the release part of your function (the else statement) will never be reached. It does this as Torque assumes if the mouse cursor is on we must need it to interact with a GUI (therefore commands bound to the mouse buttons will be ignored, so we can click on GUI buttons and the like).
I don't think you can get past this without altering source code.
Here's some script that might help you out though:
You will also want to take a look at common/client/cursor.cs to better understand how the mouse cursor works.
Lastly, here's some possibly helpful mouse related functions:
That's about all I can do for ya, best of luck!
02/14/2007 (8:03 pm)
I don't see the point in that code?The mouse is already bound to yaw & pitch. Your function simply binds those functions again if the right mouse button is pressed and does the exact same thing when it's released.
Maybe you intended to do this:
function FreeLook(%val)
{
if (%val)
{
echo ("pressed.....");
moveMap.bind(mouse, xaxis, yaw);
moveMap.bind(mouse, yaxis, pitch);
}
else
{
echo ("released...");
moveMap.Unbind(mouse, xaxis);
moveMap.Unbind(mouse, yaxis);
}
}That will bind yaw & pitch on right mouse button down and unbind yaw & pitch on release (make sure you comment out where yaw & pitch are bound normally inside of default.bind.cs i.e. let the function take care of it).
However that's not the ultimate problem here, the problem is that when the mouse is in focus the engine disables yaw & pitch so you can move the mouse pointer around (instead of the player). The other problem is once the mouse cursor is turned on, the release part of your function (the else statement) will never be reached. It does this as Torque assumes if the mouse cursor is on we must need it to interact with a GUI (therefore commands bound to the mouse buttons will be ignored, so we can click on GUI buttons and the like).
I don't think you can get past this without altering source code.
Here's some script that might help you out though:
moveMap.bind( mouse, button1, FreeLook );
function FreeLook(%val)
{
if (%val)
{
echo ("pressed.....");
canvas.cursorOff();
lockMouse(true);
disableMouse();
moveMap.bind(mouse, xaxis, yaw);
moveMap.bind(mouse, yaxis, pitch);
}
else
{
echo ("released...");
//canvas.cursorOn(); // once cursor is on mouse button looses focus
// thus you cannot release the button in order to
// turn it off again
lockMouse(false);
enableMouse();
moveMap.Unbind(mouse, xaxis);
moveMap.Unbind(mouse, yaxis);
}
}You will also want to take a look at common/client/cursor.cs to better understand how the mouse cursor works.
Lastly, here's some possibly helpful mouse related functions:
// Deactivate input. (ie, ungrab the mouse so the user can do other things. deactivateDirectInput(); // Activate input. (ie, grab the mouse again so the user can play our game. activateDirectInput(); // Enable mouse pointer. enableMouse(); // Disable mouse pointer disableMouse(); // Lock the mouse (or not, depending on the argument's value) to the window. lockMouse(bool isLocked);
That's about all I can do for ya, best of luck!
#9
02/14/2007 (8:14 pm)
Thanks a lot Tim, the right click for free look seems so commonplace in games today that I thought this would be an easily achievable feature, but I did fail to remember that torque is basically a FPS engine, so this problem now seems inevetible. Thanks again.
#10
02/14/2007 (8:32 pm)
Well then the ultimate question is, does anyone know what exactly I need to change in the source to get around the problem of letting the release function be reached. The free look is exactly what I want, however you are right, the release cannot be reached in terms of it showing the cursor again, i know it is moving because i can end up outside of my game window, it just is not showing up in game. Thanks.
#11
In the latter case (cursor is hidden), mouse input is processed by the actionMap (moveMap) settings -- which in your case is yaw and pitch for movement, and whatever is indicated for mouse0 and mouse1 for clicks.
In the former case (cursor is visible), Torque assumes the mouse needs to interact with a GUI, so the GUI captures the event before the actionMap can get it. Movement is handled by the engine (to move the cursor around on the screen), and mouse clicks are captured by the GUIs and handled by event functions like onMouseDown and onMouseUp. They never make it to the actionMap.
There are tricks you can use in the engine code to force the GUIs to ignore those mouse events and pass them along to the actionMap instead, which is how Jeff Faust's AFX solves that issue. I've incorporated those fixes in my code as well to produce this result, but it does involve some engine code changes to do that. There might be other ways around that, but I don't know of them.
02/14/2007 (8:52 pm)
The issue, as Tim points out, is that Torque handles mouse input differently when the cursor is visible compared with when it is not.In the latter case (cursor is hidden), mouse input is processed by the actionMap (moveMap) settings -- which in your case is yaw and pitch for movement, and whatever is indicated for mouse0 and mouse1 for clicks.
In the former case (cursor is visible), Torque assumes the mouse needs to interact with a GUI, so the GUI captures the event before the actionMap can get it. Movement is handled by the engine (to move the cursor around on the screen), and mouse clicks are captured by the GUIs and handled by event functions like onMouseDown and onMouseUp. They never make it to the actionMap.
There are tricks you can use in the engine code to force the GUIs to ignore those mouse events and pass them along to the actionMap instead, which is how Jeff Faust's AFX solves that issue. I've incorporated those fixes in my code as well to produce this result, but it does involve some engine code changes to do that. There might be other ways around that, but I don't know of them.
#12
02/14/2007 (9:02 pm)
Something I thought to be so simple as simply rebinding buttons has been made so complicated. I appreciate all of the help, hopefully I will be able to do this.
#13
If so, I can try to get something compiled for you today. There is one other community member I need to share some code with, and after that I can get your code to you.
Just clarify, open up the WorldEditor in game (F11). You should be able to move the camera using the right mouse button, and select objects with the left mouse button. If this is what you are looking for, I'll set it up for you.
02/15/2007 (5:26 am)
Are you using TGE 1.5 Rich?If so, I can try to get something compiled for you today. There is one other community member I need to share some code with, and after that I can get your code to you.
Just clarify, open up the WorldEditor in game (F11). You should be able to move the camera using the right mouse button, and select objects with the left mouse button. If this is what you are looking for, I'll set it up for you.
#14
02/15/2007 (1:25 pm)
You are dead on Michael, I have 1.4 now, but tomorrow, friday, i will be purchasing 1.5. If you would do that, i would be overly appreciative, I'm more of a designer than a programmer, but I am finding myself scripting and modeling/animating, want to steer as clear of coding and compiling as I can for right now. Again thanks a lot.
#15
02/17/2007 (7:26 pm)
Just wanted to post that I did get 1.5, not saying that I'm expecting you to compile it for me, just saying if you want to, that'd be great, otherwise i'm gonna grab a compiler and I guess dive in and attempt to figure it out. But if you already know how I'd love the help, thanks.
Employee Michael Perry
ZombieShortbus
These should have the exact functionality you need.