Swimming
by Luigi Rosso · in Torque Game Engine · 01/30/2002 (2:31 pm) · 2 replies
I decided to attempt making my players swim, and I had a relative success.
I simply detect in the updateMove method for the player class if the player is entirely submerged by water or not and if so I set him up to move just like a player would move underwater in Quake2 (where you move along your eye vector and you can strafe freely in the water). I don't have a swim animation so I haven't implemented a changing animation yet (eventually I'll set it up with swim forwards/backwards/left/right animations).
Now to do this I remove all acceleration calculations to derive mVelocity (property of the player class) ONLY if you are swimming. I attempted decreasing acceleration when you hit the water but that made things worse, while removing it totally makes things very controllable yet...
Things look ok if you walk into the water (when you get "mostly" submerged you start being able to swim) but if you jump into it (and I fear this is due to my acceleration hack) the interpolation goes off by a notch (just a bit but enough for you to notice a small skip as you, ghost, are updated to the corresponding server player's position).
I tried reading through the interpolation code but it seems like I'd have to know one tick prior to swimming if I will be swimming next.
Is there anyone with more Torque experience who could help me out or would have any knowledge to share which could apply to this case?
Thanks for the read,
Luigi
I simply detect in the updateMove method for the player class if the player is entirely submerged by water or not and if so I set him up to move just like a player would move underwater in Quake2 (where you move along your eye vector and you can strafe freely in the water). I don't have a swim animation so I haven't implemented a changing animation yet (eventually I'll set it up with swim forwards/backwards/left/right animations).
Now to do this I remove all acceleration calculations to derive mVelocity (property of the player class) ONLY if you are swimming. I attempted decreasing acceleration when you hit the water but that made things worse, while removing it totally makes things very controllable yet...
Things look ok if you walk into the water (when you get "mostly" submerged you start being able to swim) but if you jump into it (and I fear this is due to my acceleration hack) the interpolation goes off by a notch (just a bit but enough for you to notice a small skip as you, ghost, are updated to the corresponding server player's position).
I tried reading through the interpolation code but it seems like I'd have to know one tick prior to swimming if I will be swimming next.
Is there anyone with more Torque experience who could help me out or would have any knowledge to share which could apply to this case?
Thanks for the read,
Luigi
About the author
#2
Gravity = Acceleration. I remove gravity from the player (just about not totally). So the effect does indeed look quite good as the Torque engine progressively slows you down as you drop into the liquid. The problem is that the engine is attempting to interpolate (on the client ghost) movement of the ghost incorrectly (or correctly were he not swimming).
Here's how you can detect if the player is in a liquid:
if(inLiquid && mWaterCoverage > 0.7f)
When mWaterCoverage (how much of the bounding box is underwater) reaches 0.8 you are totally submerged. These are both properties of the Player class.
01/30/2002 (3:43 pm)
That is what I do, sorry for not making it clear.Gravity = Acceleration. I remove gravity from the player (just about not totally). So the effect does indeed look quite good as the Torque engine progressively slows you down as you drop into the liquid. The problem is that the engine is attempting to interpolate (on the client ghost) movement of the ghost incorrectly (or correctly were he not swimming).
Here's how you can detect if the player is in a liquid:
if(inLiquid && mWaterCoverage > 0.7f)
When mWaterCoverage (how much of the bounding box is underwater) reaches 0.8 you are totally submerged. These are both properties of the Player class.
Torque Owner AzraelK
Anyway heres your possible answer: torque uses a realistic physics model instead of the good old aceleration scheme from quake and other fps's so moving the aceleration values wont do any good other than messing up the equations, what you have to do is to increase the value of the friction or damping forces to simulate the body changing from air to liquid, then change it back to is normal value when it comes out of the water. Be careful not to use very big or very little values, because this will probably cause the physics engine to "blow" giving you erratic movements.
If this doesnt work as expected or you just cant find the right value, simply changing the gravity value while in the water, should be more than enough (although not as realistic) there is a tut around on how to change the individual gravity for each character.
I hope that helps! =)