Game Development Community

Mouse binding

by Justin Mosiman · in Torque Game Engine · 06/09/2006 (10:52 am) · 2 replies

Hello,

Lets say that I wanted the pitch/yaw of the camera to be updated by pressing the scroll wheel (button2) and moving the mouse. If you press the scroll wheel and move the mouse along the xaxis, it would update the yaw, and the yaxis would update the pitch. How would you bind that to the mouse? I've tried:

moveMap.bind(mouse, "button2 yaxis", updatePitch);

but that doesn't do anything at all. When I bind updatePitch to any keyboard key and the zaxis it works, so I don't think it's a problem with updatePitch.

Thanks,
Justin

#1
06/09/2006 (12:06 pm)
Torque keybindings don't work that way. You can't just assign two inputs to one function.

Here's a very simple way of achieving what you want:
function scroll(%val)
{
   if (%val == 1)
   {
      $scroll = 1;
   }
   else if (%val == 0)
   {
      $scroll = 0;
   }
}

moveMap.bind( mouse, button2, scroll );

function yaw(%val)
{
   if($scroll)
   {
      $mvYaw += getMouseAdjustAmount(%val);
   }
}

function pitch(%val)
{
   if($scroll)
      if($Pref::Input::MouseInvert)
         $mvPitch -= getMouseAdjustAmount(%val);
            else $mvPitch += getMouseAdjustAmount(%val);
}

moveMap.bind( mouse, xaxis, yaw );
moveMap.bind( mouse, yaxis, pitch );

What that code does is flag a value of scroll = true when the scroll button is held down, and when it is depressed (or not being pressed) it flags a value of scroll = false.

The yaw and pitch functions have been modified to only activate when scroll = true, in other words only work when the scroll button is held down.

Don't forget to delete dso's and your config.cs file for changes to take affect.
#2
06/09/2006 (12:13 pm)
Oh and there is no such command as updatePitch. It's just called pitch.