Game Development Community

Hold RMB + LMB To Move

by Michael S · in Torque 3D Beginner · 07/21/2013 (7:46 am) · 0 replies

Okay, so basically I want this to work like this. If the player is holding the right mouse down, you can look around on the xaxis (not the yaxis as this is iso cam type deal) and if the player is also holding the left mouse button, you start moving forward, while able to turn yourself with the right mouse button xaxis rotation stuff. AFX has this going on, and I own afx, I was trying to get this going on my own (without using afx stuff) earlier, but failed, now I am trying to use some things from afx.. This was supposed to be a quick addition, a nice little feature to make the game that much better. Its just causing me so much issues! Here is what I added in default.binds

//Afx Test------------------------------------------

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

$accum_yaw = 0;
$accum_pitch = 0;

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

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

$mouseLButtonDown = false;
$mouseRButtonDown = false;
$mouseLRButtonsDown = false;
$mouseLRButtonsWasDown = false;

function testForMouseMoveForward()
{
  if ($mouseLRButtonsDown != $mouseLRButtonsWasDown)
  {
    $mouseLRButtonsWasDown = $mouseLRButtonsDown;
    if ($mouseLRButtonsDown)
    {
      ServerConnection.clearPreSelectedObj();
      moveforward_3(1);
    }
    else
    {
      moveforward_3(0);
    }
  }
}

function mouse_btn0(%val)
{   
  $mouseLButtonDown = %val;
  $mouseLRButtonsDown = ($mouseLButtonDown && $mouseRButtonDown);

  if (hideCursor())
  {
    if (%val)
    {
      $accum_yaw = 0;
      $accum_pitch = 0;
      hideCursor(); // cursorOff();
    }
    else
    {
      if ($accum_yaw <= 0.02 && $accum_yaw >= -0.02 && $accum_pitch <= 0.02 && $accum_pitch >= -0.02)
        //afxFinishFreeTargetingMode();
      showCursor(); // cursorOn();
    }
  }
  else
  {
    if (%val)
    {
      $accum_yaw = 0;
      $accum_pitch = 0;
      ServerConnection.setPreSelectedObjFromRollover();
      hideCursor(); // cursorOff();
    }
    else
    {
      if ($accum_yaw > 0.02 || $accum_yaw < -0.02 || $accum_pitch > 0.02 || $accum_pitch < -0.02)
        ServerConnection.clearPreSelectedObj();
      else
        ServerConnection.setSelectedObjFromPreSelected();
      showCursor(); // cursorOn();
    }
  }

  testForMouseMoveForward();
}

function mouse_btn1(%val)
{  
  $mouseRButtonDown = %val;
  $mouseLRButtonsDown = ($mouseLButtonDown && $mouseRButtonDown);
  
  if (%val)
  {
    //if (afxInFreeTargetingMode())
    //  afxCancelFreeTargetingMode();
    hideCursor(); // cursorOff();
  }
  else   
    showCursor(); // cursorOn();

  testForMouseMoveForward();
}

moveMap.bind(mouse,     xaxis,      yaw);
moveMap.bind(mouse,     button0,    mouse_btn0);
moveMap.bind(mouse,     button1,    mouse_btn1);

//--------------------------------------------------

The cursor is set to on when the game starts (I did this in playgui)
This just doesn't work, any ideas or solutions?
Thanks in advance!