Game Development Community

Sprint Button Resource trouble

by Infinitum3D · in Torque Game Engine · 10/15/2008 (10:36 am) · 39 replies

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2697

Daniel Neilsen did what is apparently a very good resource, however, its not working for me. I'm using TGE1.5.2, and it should work according to mb and Christopher ross.

Everything looks straight forward, copy, build, play but my sprint button gets ignored. If I left out a bracket { or a semicolon ; it wouldn't build (right?), so I must have just put something in the wrong place. Any help at all would be greatly appreciated!

Thanks!

Tony
Infinitum3D

My player.cc www.geocities.com/infinitum3d/player.txt
Page «Previous 1 2
#1
10/15/2008 (11:46 am)
Did you run the batch files to delete your Prefs and DSOs?
#2
10/15/2008 (12:18 pm)
Your player.cc looks like it has everything in the right place. Did you add the changes to the other three files? Removed the old prefs/config, default.bind.cs.dso, etc?
#3
10/15/2008 (1:24 pm)
Thank you, but yes. I ran the batch files to delete .dso's, deleted my config file...

The only change from the tutorial I made was the keybind, and it does seem like the keybind isn't working, but I did a simple swap from

moveMap.bind(keyboard, w, moveForward);

to

moveMap.bind(keyboard, w, toggleSprint);

and still doesn't work.

The first half of the tutorial was very straightforward. Edit MoveManager.h, edit GameConnectionMoves.cc, edit player.h...

The only thing that was even the slightest bit confusing was the player.cc changes because of how specific the locations of the code changes needed to be.

I'm really stumped.

I'm gonna try a fresh TGE1.5.2 install on a different computer. Its gotta be just me!

Any other thoughts?

Thanks again,
Tony
#4
10/15/2008 (1:45 pm)
Quote:
moveMap.bind(keyboard, w, moveForward);

to

moveMap.bind(keyboard, w, toggleSprint);

That's why it isn't working. The sprint button is a modifier, you still need to have moveForward bound. It's also likely that the bind is being overwritten by another somewhere.
#5
10/15/2008 (3:25 pm)
I just tried the resource and it does work.

However the default settings leave the effect hard to notice because you are already running. To help notice the slight speedup just load up the Stronghold or Barebones map and chase Korc. You'll notice that when you "sprint" that you can catch up to and overtake him.

You may want to decrease the sprintEnergyDrain so that you can sprint for longer, and also adjust the SprintSpeedMult & SprintForceMult.

You can also add these fields into the PlayerData datablock (player.cs) for easier editing. Instead of recompiling for each change.
SprintSpeedMult = 1.2; 
SprintForceMult = 1.2;
sprintEnergyDrain = 2;
minSprintEnergy = 2;
#6
10/16/2008 (5:37 am)
@Scott, - thanks, but it also doesn't work if I bind to x or y or "alt w".

Wait, are you saying that the keybind to q (from the resource) works WITH w forward movement, so I have to press both q AND w at the same time? If that's the case then I'm just an idiot and I apologize to everyone!

@silentMike, - thanks, but I'm NOT running. If I press the key to make him sprint, nothing happens, he stands there in the default animation (breathing). I can run, strafe, backstep, but no sprinting.

-Tony
#7
10/16/2008 (5:54 am)
@Infinitum3D

That's exactly what should happen if you're not pressing whatever you have moveForward bound to. That will also happen if you the bind is being overridden by another bind to the same key. Follow the example in the comments of the resource and bind sprint to "lshift". I'm fairly certain nothing is bound to that by default so nothing should get in the way. Make sure you don't have anything else bound to your moveForward bind. Set the sprint speed and force to a higher number to make it more obvious for testing. If your code is right what should see then is your character sprinting when you hold down lshift while moving forward.

If you don't see this, then yes, you skipped a step at some point. I would recommend stepping back through the resource slowly step by step.
#8
10/16/2008 (8:54 am)
Thanks Mike. I tried binding to lshift, but it still gets ignored. No sprint, no energy drain. I raised the settings to 3.0 to overemphasize the sprint, but no help. Max energy set to 100, min sprint energy at 5, sprint energy drain 3, run energy drain 0.

I can run with W, but when I add lshift, it just keeps on running at the same rate, and energy doesn't change.

My energy bar starts out empty, and fills over the period of the first 5 or 6 seconds. I try sprinting at halfway full, and again when full. Just gets ignored.

No errors on the build OR in the console.

Either the sprint function isn't getting called at all, or my keybind isn't working. Could anything else be wrong?

Thanks!
Tony
#9
10/16/2008 (9:16 am)
If you haven't done so yet, you should add some echo messages to make sure the functions are being called.
#10
10/16/2008 (10:02 am)
I would trying adding some echo messages and check that things are getting called like Scott suggested, and yeah you have to press two keys simultaneously to sprint. All the code does is give a boost to your movement speed when you press the sprint key. If you're not moving then +20% to 0 is still 0.

I even went so far as to test it in TGEa and got it working there. Double check your spelling, sometimes something minor like that is hard to spot, especially when you get no obvious errors.
#11
10/16/2008 (11:12 am)
OK, Thanks! Great advice (can't believe I never thought of echoes)...

My echo in the toggleSprint function does return when lshift is pressed (with or without w), so my keybind is working! But no change in speed or energy level.

Funny thing- my echo is occurring twice with a single press of lshift...hmmm....

I have added the lines to my player.cs datablock. I'm trying different values, but I'm still not seeing any difference. Are my "run" variables overriding my "sprint" variables?

In player.cc I have

runEnergyDrain = 0;
If the sprintEnergyDrain is a multiplyer, it will stay 0, so maybe if I raise it to 0.1? and rebuild?

Getting closer though, I'm sure...

Tony
#12
10/16/2008 (12:32 pm)
That it echo's indicates that the function is being called at least, but it is curious that your energy is not draining. Double check that the boolean is being set for the correct variable: $mvSprint. The reason you see two echo's is because each key press is actually two actions: key down (true) and key up (false).

runEnergyDrain is the rate at which the player's energy drains per tick while running/normal moving. 0 is the default in a stock TGE player datablock, thus the energy does not drain while running. If you raise it to 0.1 that means energy will drain at a rate of 0.1 points of energy per 32 ms or there abouts. It will have no effect on sprintEnergyDrain. Anyway, you should not raise it in the source but in the player's script datablock instead.

sprintEnergyDrain is the rate at which the player's energy drains while sprinting. If it is 2 then energy drains at a rate of 2points per tick. [b]It is not a multiplyer[b] like the other sprint variables but an accumalative effect instead.

If you followed the resource and added the one missing line mentioned by SabreCyd then it should have worked. I say again that the effect is subtle and may not be as pronounced as you would think. You say you raised the sprinting variables, what did you set them to?

For testing you might want to try something like this:
SprintSpeedMult = 10;//1.8
SprintForceMult = 10;//1.2
sprintEnergyDrain = 0.5;//1;
minSprintEnergy = 2;
With these setting you can literally zip around like the Flash.
#13
10/16/2008 (2:13 pm)
I tried those settings, but again, no effect. No speed change, no energy chane.

I'll keep trying.

Tony
#14
10/16/2008 (3:32 pm)
Hmm, perplexing. I just compared and used your player.cc from the link at the top and it compiled and works for me.

Lets see what your keybind/toggle-sprint function looks like. Other than that it would have to be something you missed, misspelling, etc. in the other two files (MoveManager.h and GameConnectionMoves.cc)
#15
10/16/2008 (4:17 pm)
Function toggleSprint(%val)
{
echo("LEFT SHIFT IS PRESSED SO WE MUST BE SPRINTING");
if ( %val )
$mvSprint = true;
else
$mvSprint = false;
}


moveMap.bind( keyboard, a, moveleft );
moveMap.bind( keyboard, d, moveright );
moveMap.bind( keyboard, w, moveforward );
moveMap.bind( keyboard, s, movebackward );
moveMap.bind( keyboard, "lshift", toggleSprint ); //---Sprint
moveMap.bind( keyboard, space, jump );
moveMap.bind( mouse, xaxis, yaw );
moveMap.bind( mouse, yaxis, pitch );

geocities.com/infinitum3d/moveManager.h.txt
geocities.com/infinitum3d/gameConnectionMoves.cc.txt
geocities.com/infinitum3d/player.h.txt

Thanks!



Tony
#16
10/16/2008 (5:27 pm)
Ok the good news: those three files are ok.

The bad.
Your toggle sprint function is wrong. Take a look at your console.log. Does it report a parse error in your default.binds.cs file? I can't even do anything in game if I use your toggle sprint function: move, look, shoot, sprint, check the console,...nothing. You must still have an existing pref file in place.

The reason why there is an error there:
The Function in
Function toggleSprint(%val)
should be function. Keywords in Torque are case sensitive.

Fix that, and use the deleteDSOs.bat and the deletePrefs.bat files.
#17
10/16/2008 (6:02 pm)
No, sorry, the copy/paste must have auto capitalized it

here the whole thing

//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

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


//------------------------------------------------------------------------------
// Non-remapable binds
//------------------------------------------------------------------------------

function escapeFromGame()
{
if ( $Server::ServerType $= "SinglePlayer" )
MessageBoxYesNo( "Quit Mission", "Exit from this Mission?", "disconnect();", "");
else
MessageBoxYesNo( "Disconnect", "Disconnect from the server?", "disconnect();", "");
}

moveMap.bindCmd(keyboard, "escape", "", "escapeFromGame();");

function showPlayerList(%val)
{
if (%val)
PlayerListGui.toggle();
}

moveMap.bind( keyboard, F2, showPlayerList );
moveMap.bind( keyboard, F5, toggleParticleEditor);


//------------------------------------------------------------------------------
// Movement Keys
//------------------------------------------------------------------------------

$movementSpeed = 0.15; // m/s


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;
if (%val)
{
PlayerBody.runEnergyDrain = 0.1;
}
}

function toggleSprint(%val)
{
echo("LEFT SHIFT IS PRESSED SO WE MUST BE SPRINTING");
if ( %val )
$mvSprint = true;
else
$mvSprint = false;
}

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 yawLeftStart()
{
if( $moving == 0 )
{
$yawingLeft = true;
yawLeft();
}
}

function yawLeft()
{
$mvYaw -= 0.001;
if( $yawingLeft ) schedule( 1, 0, yawLeft );
}

function yawLeftStop ()
{
$yawingLeft = false;
}

function yawRightStart()
{
if( $moving == 0 )
{
$yawingRight = true;
yawRight();
}
}

function yawRight(%val)
{
$mvYaw += 0.001;
if( $yawingRight ) schedule( 1, 0, yawRight );
}

function yawRightStop ()
{
$yawingRight = false;
}
//-----------

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

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

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

moveMap.bind( keyboard, a, moveleft );
moveMap.bind( keyboard, d, moveright );
moveMap.bind( keyboard, w, moveforward );
moveMap.bind( keyboard, s, movebackward );
moveMap.bind( keyboard, "lshift", toggleSprint ); //---Sprint
moveMap.bind( keyboard, space, jump );
moveMap.bind( mouse, xaxis, yaw );
moveMap.bind( mouse, yaxis, pitch );
moveMap.bind( keyboard, q, turnLeft ); //---Keyboard
moveMap.bind( keyboard, e, turnRight ); //---Keyboard

//------------------------------------------------------------------------------
// Mouse Trigger
//------------------------------------------------------------------------------

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

function altTrigger(%val)
{
$mvTriggerCount1++;
}

moveMap.bind( mouse, button0, mouseFire );
//moveMap.bind( mouse, button1, altTrigger );


//------------------------------------------------------------------------------
// Zoom and FOV functions
//------------------------------------------------------------------------------

if($Pref::player::CurrentFOV $= "")
$Pref::player::CurrentFOV = 45;

function setZoomFOV(%val)
{
if(%val)
toggleZoomFOV();
}

function toggleZoom( %val )
{
if ( %val )
{
$ZoomOn = true;
setFov( $Pref::player::CurrentFOV );
}
else
{
$ZoomOn = false;
setFov( $Pref::player::DefaultFov );
}
}

moveMap.bind(keyboard, r, setZoomFOV);
moveMap.bind(keyboard, "ctrl e", toggleZoom);


//------------------------------------------------------------------------------
// Camera & View functions
//------------------------------------------------------------------------------

function toggleFreeLook( %val )
{
if ( %val )
$mvFreeLook = true;
else
$mvFreeLook = false;
}
#18
10/16/2008 (6:02 pm)
$firstPerson = true;
function toggleFirstPerson(%val)
{
if (%val)
{
$firstPerson = !$firstPerson;
ServerConnection.setFirstPerson($firstPerson);
}
}

function toggleCamera(%val)
{
if (%val)
commandToServer('ToggleCamera');
}

moveMap.bind( keyboard, z, toggleFreeLook );
moveMap.bind(keyboard, tab, toggleFirstPerson );
moveMap.bind(keyboard, "alt c", toggleCamera);


//------------------------------------------------------------------------------
// Misc. Player stuff
//------------------------------------------------------------------------------

moveMap.bindCmd(keyboard, "ctrl w", "commandToServer('playCel',\"wave\");", "");
moveMap.bindCmd(keyboard, "ctrl s", "commandToServer('playCel',\"salute\");", "");
moveMap.bindCmd(keyboard, "ctrl k", "commandToServer('suicide');", "");


//------------------------------------------------------------------------------
// Item manipulation
//------------------------------------------------------------------------------

moveMap.bindCmd(keyboard, "h", "commandToServer('use',\"HealthKit\");", "");
moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"Crossbow\");", "");
moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"Shotgun\");", "");
moveMap.bindCmd(keyboard, "3", "commandToServer('use',\"Machinegun\");", "");
moveMap.bindCmd(keyboard, "4", "commandToServer('use',\"Blaster\");", "");
moveMap.bindCmd(keyboard, "5", "commandToServer('use',\"Rifle\");", "");

$InvState = false;
function toggleInventory() {
if ($InvState == false) {
commandToServer('DisplayInventory');
$InvState = true;
} else {
Canvas.setContent( PlayGui );
$InvState = false;
}
}

moveMap.bindCmd(keyboard, "i", "toggleInventory();", "");

//--Begin Alchemy Script
$AlcState = false;
function toggleAlchemy() {
if ($AlcState == false) {
commandToServer('DisplayAlchemy');
$AlcState = true;
} else {
Canvas.setContent( PlayGui );
$AlcState = false;
}
}
moveMap.bindCmd(keyboard, "alt a", "toggleAlchemy();", "");
//--End Alchemy Script





//------------------------------------------------------------------------------
// Message HUD functions
//------------------------------------------------------------------------------

function pageMessageHudUp( %val )
{
if ( %val )
pageUpMessageHud();
}

function pageMessageHudDown( %val )
{
if ( %val )
pageDownMessageHud();
}

function resizeMessageHud( %val )
{
if ( %val )
cycleMessageHudSize();
}

moveMap.bind(keyboard, u, toggleMessageHud );
//moveMap.bind(keyboard, y, teamMessageHud );
moveMap.bind(keyboard, "pageUp", pageMessageHudUp );
moveMap.bind(keyboard, "pageDown", pageMessageHudDown );
moveMap.bind(keyboard, "p", resizeMessageHud );


//------------------------------------------------------------------------------
// Demo recording functions
//------------------------------------------------------------------------------

function startRecordingDemo( %val )
{
if ( %val )
startDemoRecord();
}

function stopRecordingDemo( %val )
{
if ( %val )
stopDemoRecord();
}

moveMap.bind( keyboard, F3, startRecordingDemo );
moveMap.bind( keyboard, F4, stopRecordingDemo );


//------------------------------------------------------------------------------
// Helper Functions
//------------------------------------------------------------------------------

function dropCameraAtPlayer(%val)
{
if (%val)
commandToServer('dropCameraAtPlayer');
}

function dropPlayerAtCamera(%val)
{
if (%val)
commandToServer('DropPlayerAtCamera');
}

moveMap.bind(keyboard, "F8", dropCameraAtPlayer);
moveMap.bind(keyboard, "F7", dropPlayerAtCamera);

function bringUpOptions(%val)
{
if (%val)
Canvas.pushDialog(OptionsDlg);
}

moveMap.bind(keyboard, "ctrl o", bringUpOptions);


//------------------------------------------------------------------------------
// Dubuging Functions
//------------------------------------------------------------------------------

$MFDebugRenderMode = 0;
function cycleDebugRenderMode(%val)
{
if (!%val)
return;

if (getBuildString() $= "Debug")
{
if($MFDebugRenderMode == 0)
{
// Outline mode, including fonts so no stats
$MFDebugRenderMode = 1;
GLEnableOutline(true);
}
else if ($MFDebugRenderMode == 1)
{
// Interior debug mode
$MFDebugRenderMode = 2;
GLEnableOutline(false);
setInteriorRenderMode(7);
showInterior();
}
else if ($MFDebugRenderMode == 2)
{
// Back to normal
$MFDebugRenderMode = 0;
setInteriorRenderMode(0);
GLEnableOutline(false);
show();
}
}
else
{
echo("Debug render modes only available when running a Debug build.");
}
}

GlobalActionMap.bind(keyboard, "F9", cycleDebugRenderMode);


//------------------------------------------------------------------------------
// Misc.
//------------------------------------------------------------------------------

GlobalActionMap.bind(keyboard, "tilde", toggleConsole);
GlobalActionMap.bindCmd(keyboard, "alt k", "cls();","");
GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");
GlobalActionMap.bindCmd(keyboard, "F1", "", "contextHelp();");
moveMap.bindCmd(keyboard, "n", "NetGraph::toggleNetGraph();", "");


//----------------------------------------------------------------
//RPGDialog Code Begin
//----------------------------------------------------------------
function TalkTo(%val)
{
if(%val)
commandToServer('RPGDialogRay');
}

moveMap.bind(keyboard, "t", TalkTo);
moveMap.bindCmd(keyboard, "ctrl 1", "SelectAnswer(1);", "");
moveMap.bindCmd(keyboard, "ctrl 2", "SelectAnswer(2);", "");
moveMap.bindCmd(keyboard, "ctrl 3", "SelectAnswer(3);", "");
moveMap.bindCmd(keyboard, "ctrl 4", "SelectAnswer(4);", "");
moveMap.bindCmd(keyboard, "ctrl 5", "SelectAnswer(5);", "");
moveMap.bindCmd(keyboard, "ctrl 6", "SelectAnswer(6);", "");
moveMap.bindCmd(keyboard, "ctrl 7", "SelectAnswer(7);", "");
moveMap.bindCmd(keyboard, "ctrl 8", "SelectAnswer(8);", "");
moveMap.bindCmd(keyboard, "ctrl 9", "SelectAnswer(9);", "");
moveMap.bindCmd(keyboard, "ctrl 0", "SelectAnswer(10);", "");

function OutOfRPGDialogFunction(%Number)
{
switch(%Number)
{
case 1: commandToServer('use',"Crossbow");
case 2: %Number=0;//Does nothing... just a placeholder.
case 3: %Number=0;//Does nothing... just a placeholder.
case 4: %Number=0;//Does nothing... just a placeholder.
case 5: %Number=0;//Does nothing... just a placeholder.
case 6: %Number=0;//Does nothing... just a placeholder.
case 7: %Number=0;//Does nothing... just a placeholder.
case 8: %Number=0;//Does nothing... just a placeholder.
case 9: %Number=0;//Does nothing... just a placeholder.
case 0: %Number=0;//Does nothing... just a placeholder.
}
}
//----------------------------------------------------------------
//RPGDialog Code End
//----------------------------------------------------------------

//----------------------------------------------------------------
//Allows us to view our stats
//----------------------------------------------------------------
moveMap.bind(keyboard, m, toggleStatsGUI);
//----------------------------------------------------------------
#19
10/16/2008 (6:54 pm)
Line# 39 - $movementSpeed = 0.15; // m/s

That could be the culprit. What that does is modify (multiply) your movement speed which is determined by a number of factors, and in this case makes it extremely slow. For example, the default maxForwardSpeed is 14 m/s. 14 * 0.15 = 2.1 m/s - a slow walk. When you add the 20% for sprinting you only get up to 2.52 m/s - still a slow walk.

Set $movementSpeed = 1; and give it a try.
#20
10/17/2008 (4:32 am)
Stil no sprint or energy drain. I did zip around, but the sprint "lshift" didn't change anything.

I'm still trying tho...
Page «Previous 1 2