Game Development Community

Swim animations

by Jonathon Stevens · in Torque Game Engine Advanced · 10/16/2006 (6:34 pm) · 5 replies

On the Adding new positions and moves; ie swim, crouch, crawl, prone resource I'm having an issue with getting the player to swim.

The issue isn't in the resource at all it appears, but in TSE ms4. When I am in water the mWaterCoverage variable is always 0.

This line determines if you are actually IN water:

if( mWaterCoverage >= 0.9 )

So, obviously, the player never thinks it's actually IN water so therefore the animation scripts for use while in water never trigger.

Thoughts?

About the author

With a few casual games under his belt as CEO of Last Straw Productions, Jonathon created the increasingly popular Indie MMO Game Developers Conference.


#1
10/16/2006 (11:31 pm)
It doesn't work in TSE. All of the waterblock functions in TSE (including the iswet flag for weapons, and watercoverage) are basically non-functional. Anything that is related to water as a result is more or less non-functional (bubbles, splashes, etc).

We needed to get boats and swimimng working for a project I worked on a while back on TSE, and only needed players to be able to swim on top of the water. So what I wound up doing for that project, which might work for you, is creating an invisible (translucent) DIF object underneath the water, at about 2.5 meters underwater. I then placed vehicle blockers around the edge of the water to keep boats from "driving" out of the water. I then added a function to the player:

bool Player::checkIfSwimming()
{
	Point3F curPos = getPosition();

   if (pointInWater( Point3F(curPos.x, curPos.y, (curPos.z + 1.0f) ))) 
   {
	//   Con::printf("We ARE Swimming");
	   return 1;
   }
	//	Con::printf("We ARE NOT Swimming");
	   return 0;
}

and then did this:

mSwimming = checkIfSwimming();
//	  Con::printf("Swimming = %d", mTest);
	  if (mSwimming)
	  {
		 	setActionThread(PlayerData::SwimAnim,true,false,false);
	  }

Then I modified the PointInWater to look like this:

bool Player::pointInWater( Point3F &point )
{
   SimpleQueryList sql;
   if (isServerObject())
      gServerSceneGraph->getWaterObjectList(sql);
   else
      gClientSceneGraph->getWaterObjectList(sql);

   for (U32 i = 0; i < sql.mList.size(); i++)
   {
      WaterBlock* pBlock = dynamic_cast<WaterBlock*>(sql.mList[i]);

 //     if (pBlock && pBlock->getLiquidType() == WaterBlock::eWater )
//      if (pBlock)
//      {
         if (pBlock->isUnderwater( point ))
			{
				return true;
			}
 //     }

   }

   return false;
}

Also make sure that you add the checkifswimming and mswimming to player.h, as well as adding a swim animation to your action animations definitions in player.cpp and player.h.

That code basically made it so when a player ran into the water and they got submerged at waist level it would start playing a new animation which made them appear to be wading just underneath the water, and when they became too high to do that it would move back into a run.

Note: I'm at work, I haven't tested that code with MS4, though I doubt anything has changed that would break it.
#2
10/17/2006 (12:20 am)
Thanks for the tips J.C.

I was under the impression that ms4 was feature-complete. I take it this is a known issue?

Since I'm a nub to that part of the code, I might just hack away at it and see if I can't find why the waterblock functions aren't working. Is there a post following the bug? I'm about to do a search, but might as well ask now while I'm posting ;).
#3
10/17/2006 (4:13 am)
There are a few things that need some tweaking. Projectile decals also don't work out of the box, nor do splashes or footpuff emitters, maybe a couple other things. Most of these are pretty easy to work around though.
#4
10/18/2006 (1:53 pm)
For my clarification, the changes in the previously linked topic do not work at all in TSE right?

I ask because I'm working on a team that started a game in TGE decided they needed shaders and moved it to TSE and the game takes place entirely underwater (you're a fish).

If I wanted to add swimming, would I just need to copy and paste in the lines JC has or is there stuff needed from the previous swimming mod? I've been pulling my hair out trying to get that old swimming stuff to work with TSE.

Thanks in advance!

-Matthew Barney
USC IMD
"Original Fin" Team
#5
10/18/2006 (8:41 pm)
The code I had there works on its own, you wouldn't need the old code. Though you would also need to add in the swimming animation to your action animation as is shown in the old resource.