Game Development Community

Speed buff

by Sean Oloughlin · in Torque Game Engine · 05/16/2012 (9:46 pm) · 4 replies

Hi all,

i need help in making a 'Speed buff' function that when i call it to speed up the players movement speed for a certain amount of time. Any help will be MUCH APPRECIATED!,

thanks for your time.

#1
05/18/2012 (12:40 pm)
I did something like this years ago in an old TGE project. I don't have a checkout of T3D on this machine to reference so I can just give you the high level of the direction on how to go about this.

Basically what you want to do is add a new member variable to the player class and expose it to the console to manipulate it during the game in the scripts. This new variable will be your speed buff factor (when I did this I was actually implementing differing agility for players, another name but same concept).

Now the important part is to make sure this done to the Player class, not the PlayerData. PlayerData is the datablock which can't be manipulated in the middle of a game. Now locate where the player's speed is used for movement (sorry can't remember where that is directly off the top of my head). Here you'll want to change the final speed that used to (playerSpeed * speedBuffFactor). Your speedBuffFactor should be initialized to 1.0 so that by default your player's speed will be normal.

Now just write a new ConsoleMethod that will change the value of speedBuffFactor to whatever value you pass it. Then you can make your player slower or faster and easily by calling that method from script and return them to normal by calling it again and passing it 1.0.

There are multiple sprinting resources on the site that will help give you a leg up on the code side for some examples. Most of them have been written against TGE, so they won't be immediately compatible in T3D, but they should help show you where to look.
#2
05/18/2012 (5:54 pm)
thanks mate for your quick reply i pretty much did exactly what you said with this resource http://www.garagegames.com/community/resources/view/8463
now i need to implement a timer for the buff to only last a certain amount of time but that shouldn't be too hard,

thanks alot.
#3
05/18/2012 (6:33 pm)
If you don't need to visualize it like a countdown or an alert of some kind that the player is about to return to their normal speed then I'd probably go with scheduling the second call to the console method right after the call that applies the buff.
#4
05/18/2012 (9:31 pm)
u can test it:

function boostMoveforward(%val)
{
	
	if(%val)
	{
      ServerConnection.getControlObject().getDataBlock().setFieldValue(maxForwardSpeed,100);
        //$mvForwardAction = %val * $movementSpeed;//to boost+movement uncomment it.u do not have to press "w" or "up" key to move
	}
	else
	{	
		ServerConnection.getControlObject().getDataBlock().setFieldValue(maxForwardSpeed,8);
	}

}
moveMap.bind(keyboard, "q", boostMoveforward);

as said by scott,
it will not actually change the speed property of player.it will change value of datablock(from which player class get the value ).and datablock changes have to tranasfer to other clients also.so it is not multiplayer supported.u have to add some code for that.
also it will boost other player object like Aiplayer.that is another side effect of this.

i will try to find the proper one(through player object's properties) later.


[edit]
there was some copy paste mistake.now fixed