Easy Swimming
by Sam Guffey · in Torque Game Engine · 08/16/2002 (9:31 pm) · 13 replies
Here is the easiest and best looking swim tech I came up with. There is very little editing as you can see.
in player.cc at the end of the function "updateMove" add this
Next just add the swim function in player.cs
You can add your swim animation in there later if you wish with ease.
in player.cc at the end of the function "updateMove" add this
if(mWaterCoverage >= 0.8f)
{
if(move->y > 0) // Forward
{
Con::executef(mDataBlock,3,"swim",scriptThis());
setActionThread((mVelocity.len() < 0.5) ? PlayerData::StandJumpAnim: PlayerData::JumpAnim, true, false, true);
}
}Next just add the swim function in player.cs
function Armor::swim(%this, %obj)
{
%position = %obj.getTransform();
%pos = getWords(%position, 0, 2);
%eye = %obj.getEyeVector();
%xx = getWord(%eye, 0) * 1.3;
%yy = getWord(%eye, 1) * 1.3;
%zz = getWord(%eye, 2) * 1.3;
%vec = (%xx SPC %yy SPC %zz);
%obj.applyImpulse(%pos, VectorScale(%vec, %obj.getDataBlock().mass));
}You can add your swim animation in there later if you wish with ease.
About the author
#2
08/17/2002 (2:31 am)
btw i'm not sure if I mighta messed something up ... but why can I swim so fast I can jump out of the water and not see the ground I can jump out so far lol
#3
08/17/2002 (2:36 am)
Trevor, you can do something like:Con::getVariable("fps::real");orCon::getLocalVariable(varName);but I haven't tried the latter, but I guess you can call it like
Con::getLocalVariable("%player.foo");
#4
08/17/2002 (2:59 am)
Man I wish I knew more about C++ ... I got a little rusty since I didnt use it forever ... how would the code know what %player is?
#5
but it seems you have to call it without the %, cause that seems to be appended in the function itself...
So it would be:
08/17/2002 (3:05 am)
Well, the console knows all your vars, and what these functions do is a simple name lookup / string comparison in the StringTable (where all vars are stored)...but it seems you have to call it without the %, cause that seems to be appended in the function itself...
So it would be:
const char* foo = Con::getLocalVariable("player.foo");
#6
08/17/2002 (3:06 am)
btw i'm trying to make is so that when you tread water you move slower, no gravity effects you, and to hopefully make it so when you move in the water you dont keep going lol
#7
08/17/2002 (3:10 am)
ah I see .. thx a ton for your help!
#8
edit: lol I looked like at a diagnal at the ground and starting swimming in a horizontal line ... anyone tried this yet?
08/17/2002 (3:43 am)
sorry about posting so much but now I like swim almost sideways loledit: lol I looked like at a diagnal at the ground and starting swimming in a horizontal line ... anyone tried this yet?
#9
08/17/2002 (9:04 am)
All Torque C++ related discussions belong in the private SDK forums.
#10
The "1.3" is how hard is pushes you, you may need to adjust this number to suit your needs.
08/17/2002 (4:28 pm)
(%xx = getWord(%eye, 0) * 1.3;)The "1.3" is how hard is pushes you, you may need to adjust this number to suit your needs.
#11
I know about the 1.3 thing .... hhmm ... it's more of a momentum thing even though I took acceleration off if your in water. Btw i'm having lots of fun with your code lol :P ... nice work :D.
I also need to figure out how to make it so that if you hit the water surface going up, you dont fly high into the sky lol.
Good way to get something started though :D
08/17/2002 (6:39 pm)
mike? Were you referring to me?I know about the 1.3 thing .... hhmm ... it's more of a momentum thing even though I took acceleration off if your in water. Btw i'm having lots of fun with your code lol :P ... nice work :D.
I also need to figure out how to make it so that if you hit the water surface going up, you dont fly high into the sky lol.
Good way to get something started though :D
#12
Thanks again, you rock! :)
07/24/2004 (9:47 pm)
Thank you for posting this code snippet, I got it working correctly the first time. Ok, now on to the other couple hundred things I need to do yet... :PThanks again, you rock! :)
#13
I haven't added special swim animations, yet, but still .. thanks a bunch!! you da bomb
08/10/2004 (12:31 pm)
Thanks Sam.. Added the code and it worked a treat!I haven't added special swim animations, yet, but still .. thanks a bunch!! you da bomb
Trevor "PointDestruction"
Ok, you now how in the actual game files how you can do variables like %player.whatever and have whatever have a value. How can you read that value from the engine's side? Thx in advance.
Btw, i'll try your code out :D