Charge Jump
by James Laker (BurNinG) · 05/26/2005 (11:23 pm) · 36 comments
Wanted to do this a while ago, but canned the project do to real life taking
way too much time :( Anyway... I promised Adam Brookman ;)
So let's get right to it...
Open up 'example\\client\scripts\default.bind.cs' and
change 'function jump(%val)' to look like this:
As you can see we call the JumpCharge on the server (scripting) side. Now open
example\starter.lighthouse\server\scripts\commands.cs. This is where we usually
store client function calls as you'll see.
Now add this function in there with the rest:
Now we add a new variable in the Player class which holds the Jumpcharge variable.
So in 'class Player: public ShapeBase' (player.h) in the Protected section add:
Now in the Public section we add the setter (and the Optional Getter)
On to the player.cc. We add the Functions here and initialize the value.
in Player::Player() add the following
And add this there somewhere to. You'll see the place.
We need to expose these 2 functions to the script for the call in
ServerCmdJumpCharge(%client,%val) to '%client.player.setJumpCharge(%val);'
to work (where the other ConsoleMethods are) :
Almost done... To apply the force to the actuall jump action we go to
'void Player::updateMove(const Move* move)'. That should make sense :)
Change this piece of code, but before you do... sit 30secs and go through it.
It isn't too hard to understand, right?:
The Jumping here is a bit strong... But you'll nail Trinity in a Highjump competition!
Compile, run and Juuummmmmppppp!
Also try adding the resource for 'Air Control' posted by F.W. Hardijzer for a cooler
effect!
NOTE! Delete *.dso for the script files you've changed if for some reason it doesn't
work. If you have any problems just give me a shout.
Cheers
Burning
way too much time :( Anyway... I promised Adam Brookman ;)
So let's get right to it...
Open up 'example\
change 'function jump(%val)' to look like this:
function jump(%val)
{
//if %val = 0 the button is released (OnkeyUp); 1 if pressed (onKeydown)
if (%val)
{
//We Save the time when we pressed the key in $startTime
$startTime = getSimTime();
echo("Starting Jump : " @ $startTime);
}
else
{
//WE Save Time when the key was released in $endTime
$endTime = getSimTime();
//Subtract the 2 to find out how long we held the key
$chargeTime = $endTime - $startTime;
echo("Charge Time : " @ $chargeTime);
CommandToServer('JumpCharge',$chargeTime);
// I know the following is weird, but it's a hack and i don't know any better.
// I works fine though!
$mvTriggerCount2++; //Adds the JumpTrigger....
$mvTriggerCount2++; //Removes Trigger again so Kork doesn't keep hopping crazy!
}
}As you can see we call the JumpCharge on the server (scripting) side. Now open
example\starter.lighthouse\server\scripts\commands.cs. This is where we usually
store client function calls as you'll see.
Now add this function in there with the rest:
function ServerCmdJumpCharge(%client,%val)
{
// We handle the Maximums and minimums here so the Client can't cheat or
// send crazy values
// 2500 = 2.5secs
if (%val > 2500)
{
%val = 2500;
}
//Divide it to something reasonable (change this to alter the jump strength)
%val = %val / 450;
if (%val < 1)
{
%val = 1;
}
// Okay here we make a call to code... this means the clients' player class
// is calling the setJumpCharge in that class. (getJumpCharge is optional)
%client.player.setJumpCharge(%val);
echo("Jump Charge : " @ %client.player.getJumpCharge());
}Now we add a new variable in the Player class which holds the Jumpcharge variable.
So in 'class Player: public ShapeBase' (player.h) in the Protected section add:
F32 mJumpCharge;
Now in the Public section we add the setter (and the Optional Getter)
F32 getJumpCharge(); void setJumpCharge(F32 JumpCharge);
On to the player.cc. We add the Functions here and initialize the value.
in Player::Player() add the following
mJumpCharge = 1;
And add this there somewhere to. You'll see the place.
F32 Player::getJumpCharge()
{
return mJumpCharge;
}
void Player::setJumpCharge(F32 JumpCharge) //Optional
{
//Only if Client
if (!isGhost())
{
mJumpCharge = JumpCharge;
}
}We need to expose these 2 functions to the script for the call in
ServerCmdJumpCharge(%client,%val) to '%client.player.setJumpCharge(%val);'
to work (where the other ConsoleMethods are) :
ConsoleMethod( Player, setJumpCharge, void, 2, 4, "(F32 Jumpcharge)")
{
object->setJumpCharge(dAtof(argv[2]));
}
//Optional
ConsoleMethod( Player, getJumpCharge, F32, 0, 0, "(Return the current JumpCharging Var)")
{
return object->getJumpCharge();
}Almost done... To apply the force to the actuall jump action we go to
'void Player::updateMove(const Move* move)'. That should make sense :)
Change this piece of code, but before you do... sit 30secs and go through it.
It isn't too hard to understand, right?:
F32 impulse = mDataBlock->jumpForce / mMass;
if (dot <= 0)
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale;
else
{
acc.x += pv.x * impulse * dot;
acc.y += pv.y * impulse * dot;
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale;
}to this:F32 impulse = mDataBlock->jumpForce / mMass;
if (dot <= 0)
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale * mJumpCharge;
else
{
acc.x += pv.x * impulse * dot;
acc.y += pv.y * impulse * dot;
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale * mJumpCharge;
}The Jumping here is a bit strong... But you'll nail Trinity in a Highjump competition!
Compile, run and Juuummmmmppppp!
Also try adding the resource for 'Air Control' posted by F.W. Hardijzer for a cooler
effect!
NOTE! Delete *.dso for the script files you've changed if for some reason it doesn't
work. If you have any problems just give me a shout.
Cheers
Burning
About the author
#22
Here is a the basic system I would use to do it:
Create a new variable and manipulate it so it is how much energy to take based on the power of the jump.
Then, assuming there is something to call to take energy, (If there isn't I'd create one.) use the function and give it your variable.
I would create/get my energy consumption somewhere based on where I could call the energy drain function.
Simplest way to do it I think.
I imagine I haven't really given you much to go on, but I don't have much here either so there's not much I can do.
08/21/2005 (12:07 pm)
I'm sorry. I don't even have torque, I was just commenting because I thought it was interesting and the idea made sense outside of torque. I'm not sure what you have to work with so I can't even really give you a good guess.Here is a the basic system I would use to do it:
Create a new variable and manipulate it so it is how much energy to take based on the power of the jump.
Then, assuming there is something to call to take energy, (If there isn't I'd create one.) use the function and give it your variable.
I would create/get my energy consumption somewhere based on where I could call the energy drain function.
Simplest way to do it I think.
I imagine I haven't really given you much to go on, but I don't have much here either so there's not much I can do.
#23
01/13/2006 (5:45 pm)
Does this start the jump while you are pressing it down and then the longer you hold it down, the longer you stay in the air?
#24
01/15/2006 (10:11 pm)
Nope... When you press the jump button you won't jump until you release the buttton. The longer you hold, the higher.
#25
____________________________________________________________________________________
We need to expose these 2 functions to the script for the call in
ServerCmdJumpCharge(%client,%val) to '%client.player.setJumpCharge(%val);'
to work (where the other ConsoleMethods are) :
ConsoleMethod( Player, setJumpCharge, void, 2, 4, "(F32 Jumpcharge)")
{
object->setJumpCharge(dAtof(argv[2]));
}
//Optional
ConsoleMethod( Player, getJumpCharge, F32, 0, 0, "(Return the current JumpCharging Var)")
{
return object->getJumpCharge();
}
Almost done... To apply the force to the actuall jump action we go to
'void Player::updateMove(const Move* move)'. That should make sense :)
Change this piece of code, but before you do... sit 30secs and go through it.
It isn't too hard to understand, right?:
F32 impulse = mDataBlock->jumpForce / mMass;
if (dot <= 0)
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale;
else
{
acc.x += pv.x * impulse * dot;
acc.y += pv.y * impulse * dot;
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale;
}
to this:
F32 impulse = mDataBlock->jumpForce / mMass;
if (dot <= 0)
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale * mJumpCharge;
else
{
acc.x += pv.x * impulse * dot;
acc.y += pv.y * impulse * dot;
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale * mJumpCharge;
}
________________________________________________________________________________
But which file do I make thses changes in?
01/21/2006 (4:56 pm)
I am having a few problems knowing where to put this snippets into the code. Your saying to:____________________________________________________________________________________
We need to expose these 2 functions to the script for the call in
ServerCmdJumpCharge(%client,%val) to '%client.player.setJumpCharge(%val);'
to work (where the other ConsoleMethods are) :
ConsoleMethod( Player, setJumpCharge, void, 2, 4, "(F32 Jumpcharge)")
{
object->setJumpCharge(dAtof(argv[2]));
}
//Optional
ConsoleMethod( Player, getJumpCharge, F32, 0, 0, "(Return the current JumpCharging Var)")
{
return object->getJumpCharge();
}
Almost done... To apply the force to the actuall jump action we go to
'void Player::updateMove(const Move* move)'. That should make sense :)
Change this piece of code, but before you do... sit 30secs and go through it.
It isn't too hard to understand, right?:
F32 impulse = mDataBlock->jumpForce / mMass;
if (dot <= 0)
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale;
else
{
acc.x += pv.x * impulse * dot;
acc.y += pv.y * impulse * dot;
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale;
}
to this:
F32 impulse = mDataBlock->jumpForce / mMass;
if (dot <= 0)
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale * mJumpCharge;
else
{
acc.x += pv.x * impulse * dot;
acc.y += pv.y * impulse * dot;
acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale * mJumpCharge;
}
________________________________________________________________________________
But which file do I make thses changes in?
#26
Again in player.cc, do a search for void Player::updateMove around line 1380.
01/25/2006 (10:11 pm)
There are other Console methods in the player.cc around lines 3600-3700... Add the console methods there.Again in player.cc, do a search for void Player::updateMove around line 1380.
#27
03/12/2006 (12:02 pm)
Can anybody help with where the following code goes?F32 Player::getJumpCharge()
{
return mJumpCharge;
}
void Player::setJumpCharge(F32 JumpCharge) //Optional
{
//Only if Client
if (!isGhost())
{
mJumpCharge = JumpCharge;
}
}
#28
Just look for the the other Player class functions.
Right at the bottom should work fine.
03/13/2006 (2:23 am)
Anywhere in the player.cc file.Just look for the the other Player class functions.
Right at the bottom should work fine.
#29
03/13/2006 (7:25 am)
@Burning-thank you
#30
thanks for posting, i learned a lot from this!
04/21/2006 (4:00 pm)
Fantastic! works great in TGE1.4 I had to move the function serverCmdTeleportPlayer from scripts/commands.cs to game.cs b/c i wasn't using a commands.cs in my starter project. The console told me the function wasn't defined so i was able to fix it. It would be cool to route a player crouch into the jump charge so you would know when someone is getting ready to jump.thanks for posting, i learned a lot from this!
#31
I'll see if the crouching request you have is a quick one. I still want the jump charge to use energy too. Haven't gotten round to that either.
04/24/2006 (12:23 am)
Glad it worked. I'll see if the crouching request you have is a quick one. I still want the jump charge to use energy too. Haven't gotten round to that either.
#32
04/30/2006 (3:22 pm)
Very cool. Thanks very much.
#33
12/24/2006 (10:13 pm)
#34
01/09/2007 (2:30 am)
What seems to be the problem Jamie?
#36
Either way am I the only one that thinks there's another way to skin this cat, the code seems way too complex for such a small feat.
07/29/2009 (2:39 pm)
I was under the impression this was a Super Mario Bros.-esque Jump, it sounds like a Mario 2 hold down and flash charge jump.Either way am I the only one that thinks there's another way to skin this cat, the code seems way too complex for such a small feat.

Torque 3D Owner Alaric Karczag