Game Development Community

Mouse fucntions / controls

by Tim Tebow · in Torque Game Engine · 04/30/2007 (8:18 am) · 1 replies

Hey guys,

Have 2 questions...

1 - Should I be posting in the private section to get more replys to questions? Im assuming just the general forum is available to anyone to post, and here is for everyone that owns one of the torque products?

2 - Im having problems with getting my character to move with both mouse buttons being held down. I have searched on google and in the tdn but having no luck finding what I need. If you know of a place for me to look ill deffinitly do the researching but heres my code let me know if you see any problems..

What it is doing is it will walk when both mouse buttons are pushed but when I release the mouse buttons it will just continue to walk until I hit the arrow keys or "w" and that seems to reset the forward motion part of the code.

// Movement Keys

$movementSpeed = 1; // m/s

$leftMouseIsDown = 0;
$rightMouseIsDown = 0;

function rightClick(%val)
{
    if(%val)
    {
           $rightMouseIsDown = 1;

           if($leftMouseIsDown && $rightMouseIsDown)
                  $mvForwardAction = %val * $movementSpeed;
    }
    else
    {
        $rightMouseIsDown = 0;
    }
}
function leftClick(%val)
{
    if(%val)
    {
           $leftMouseIsDown = 1;
           
           if($leftMouseIsDown && $rightMouseIsDown)
                  $mvForwardAction = %val * $movementSpeed;
    }
    else
        $leftMouseIsDown = 0;
}




function setSpeed(%speed)
{
   if(%speed)
      $movementSpeed = %speed;
}

function moveleft(%val)
{
   $mvLeftAction = %val * $movementSpeed;
}

function moveright(%val)
{
   $mvRightAction = %val * $movementSpeed;
}

function moveforward(%val)
{
   $mvForwardAction = %val * $movementSpeed;
}

function movebackward(%val)
{
   $mvBackwardAction = %val * $movementSpeed;
}

function moveup(%val)
{
   $mvUpAction = %val * $movementSpeed;
}

function movedown(%val)
{
   $mvDownAction = %val * $movementSpeed;
}

function turnLeft( %val )
{
   $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function turnRight( %val )
{
   $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function panUp( %val )
{
   $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function panDown( %val )
{
   $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function getMouseAdjustAmount(%val)
{
   // based on a default camera fov of 90'
   return(%val * ($cameraFov / 90) * 0.01);
}

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

function pitch(%val)
{
   $mvPitch += getMouseAdjustAmount(%val);
}

function jump(%val)
{
   $mvTriggerCount2++;
}

function mouseTrigger(%val)
{
  $mvTriggerCount0++;
}

moveMap.bind( keyboard, a, moveleft );
moveMap.bind( keyboard, d, moveright );
moveMap.bind( keyboard, w, moveforward );
moveMap.bind( keyboard, s, movebackward );
moveMap.bind( keyboard, space, jump );
movemap.bind(mouse, button0, leftclick)
movemap.bind(mouse, button1, rightclick)
moveMap.bind( mouse, xaxis, yaw );
moveMap.bind( mouse, yaxis, pitch );
//moveMap.bind( mouse, button0, mouseTrigger );
When I get home ill post my code for some reason its acting all goofy when i copy it from my other post which is located at garagegames.com/mg/forums/result.thread.php?qt=61166



Thanks

#1
04/30/2007 (12:10 pm)
Talking to you on msn now... edited
Thanks,
Rob / SoulByteGames Company