Game Development Community

Multiplayer keybindings

by Jhansi · in Torque Game Engine · 04/18/2008 (5:11 am) · 3 replies

I have two players in my game. first player is moving with arrow keys but problem with second player it is not moving.

i am sending my code plz suggest me where i have gone wrong...


if ( isObject( moveMap ) )
movemap.delete();
new ActionMap(moveMap);

function moveLeft(%val, %player)
{
$mvLeftAction[%player] = %val* $playermovementSpeed;
}

function player0MoveLeft(%val)
{
moveLeft(%val, 0);
}

function player1MoveLeft(%val)
{
moveLeft(%val, 1);
}

function moveRight(%val, %player)
{
$mvRightAction[%player] = %val* $playermovementSpeed;
}

function player0MoveRight(%val)
{
moveRight(%val, 0);
}

function player1MoveRight(%val)
{
moveRight(%val, 1);
}
function moveForward(%val, %player)
{
$mvForwardAction[%player] = %val* $playermovementSpeed;
}

function player0MoveForward(%val)
{
moveForward(%val, 0);
}

function player1MoveForward(%val)
{
moveForward(%val, 1);
}

function moveBackward(%val, %player)
{
$mvBackwardAction[%player] = %val* $playermovementSpeed;
}

function player0MoveBackward(%val)
{
moveBackward(%val, 0);
}

function player1MoveBackward(%val)
{
moveBackward(%val, 1);
}

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, left, moveleft );
moveMap.bind( keyboard, right, moveright );
moveMap.bind( keyboard, up, moveforward );
moveMap.bind( keyboard, down, movebackward );
moveMap.bind( keyboard, space, jump );

//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, xaxis, yaw );
moveMap.bind( mouse, yaxis, pitch );
moveMap.bind( mouse, button0, mouseTrigger );


This is my config.cs

if (isObject(moveMap)) moveMap.delete();
new ActionMap(moveMap);
moveMap.bindCmd(keyboard, "escape", "", "escapeFromGame();");
moveMap.bind(keyboard, "left", moveLeft);
moveMap.bind(keyboard, "right", moveRight);
moveMap.bind(keyboard, "up", moveForward);
moveMap.bind(keyboard, "down", moveBackward);
moveMap.bind(keyboard, "space", jump);
moveMap.bind(keyboard, "z", toggleFreeLook);
moveMap.bind(keyboard, "tab", toggleFirstPerson);
moveMap.bind(keyboard, "alt c", toggleCamera);
moveMap.bind(keyboard, "f8", dropCameraAtPlayer);
moveMap.bind(keyboard, "f7", dropPlayerAtCamera);
moveMap.bind(mouse0, "xaxis", yaw);
moveMap.bind(mouse0, "yaxis", pitch);
moveMap.bind(mouse0, "button0", mouseTrigger);

About the author

Recent Threads

  • Controlling two players

  • #1
    04/18/2008 (12:50 pm)
    You're thinking too much. Key bindings are inside of the Client folder therefore they are separate and independent for each client. The script that comes with the starter.fps package with TGE will work just fine in a multiplayer setting without modification. Each player can have their own (different) key bindings and everything will still work fine. The "$mv" variables are automatically scoped to each individual clients and Torque will handle updating the position of the appropriate player and sending it to any other connected clients.
    #2
    04/18/2008 (1:14 pm)
    I think he may be referring to two people playing at the same keyboard (one on WASD and the other on the arrow keys) - older games used to do that for multiplayer. I wish I could answer, but I do know that someone else was asking on the forums as well.
    #3
    04/18/2008 (1:37 pm)
    Wow, that never even entered my mind... ok then. That's a whole different ball of wax that will probably require more work than tweaking the default.bind.cs script. I don't believe is designed, on a internal level, to expect to have more than one control object on a single Connection.