Game Development Community

Player movement- forward and back using Mouse Wheel

by Ray Taylor · in Torque 3D Professional · 01/24/2014 (6:39 pm) · 3 replies

I would like to use the mouse wheel to control variable speed for forward and backward movement. I am using dual speed now using post # 11 under www.garagegames.com/community/forums/viewthread/109207 but thought the mouse wheel would be great for complete control of variable speed movement. I am not a programmer but I can add things once I see how someone else has done it. So, has anyone done this before or want to write the code for how to do it? It would make for a great resource.

No engine code changes, again, I am not a programmer and I can never get the engine recompiled correctly.

Thanks in advance for the help!

#1
01/25/2014 (2:17 pm)
Have you had a read of default.bind? Have a look at lines which bind the WASD keys and the functions they're bound to. There's also a way to bind the scroll-wheel to a function call. See if that helps!
#2
01/26/2014 (7:13 pm)
Thanks Daniel, before my post I searched for mouseWheel in Torsion but I didn't notice that I had typed in mouse wheel, two words, instead of mousewheel, one word. My search came back null. Your link helped me find my error and lead me to start guessing at how to use the mouse wheel. All my guessing worked and here is the code for default.bind.cs
//---Controls variable Forward and Backward Speed with Mouse Wheel------

function mouseWheelControlsFwdBackSpeed(%val)
{
   %mouseWheelControlsFwdBackSpeedAdj = getMouseAdjustAmount(%val);
   
// Clamp and scale
   %mouseWheelControlsFwdBackSpeedAdj = mClamp(%mouseWheelControlsFwdBackSpeedAdj, -m2Pi()+0.01, m2Pi()-0.01);
   %mouseWheelControlsFwdBackSpeedAdj *= 0.25;   // was 0.5 in yaw mode, adjust sensitivity


   $mvForwardAction += %mouseWheelControlsFwdBackSpeedAdj;
//      echo("forwardspeed = " @$mvForwardAction);
   
// the if statement makes stopping easier because it gives a range for stopping   
   if ($mvForwardAction > -.03 && $mvForwardAction < 0.03 ) 
   {
//      echo("stoppingspeed = " @$mvForwardAction);
      $mvForwardAction = 0;
   }
}


moveMap.bind( mouse, "zaxis", mouseWheelControlsFwdBackSpeed );

Make sure you aren't using mouseWheelWeaponCycle and then unbind it.
Always remember to delete config.cs file when updating default.bind.cs, at least in Pro 1.1.
#3
01/27/2014 (12:16 am)
Glad you got it working! :)