Game Development Community

T3D 1.1 Beta 3 - Player picks wrong animation if mount hasn't come through yet - RESOLVED

by David Wyand · in Torque 3D Professional · 01/17/2011 (11:54 pm) · 2 replies

Build: 1.1 Beta 3 Pro

Platform: Windows XP, Vista, 7

Target: In a client/server game

Issues: If a Player is mounted on the server to a just created object, and the Player was also given a special mount action animation (such as sitting), it is likely that all clients will see that Player in a Root action sequence while mounted, especially if that Player was in motion prior to mounting.

Steps to Repeat:
This one needs a fair bit of setup to repeat. First, you'll need a player with some mount animation, such as sitting. Next you'll need an object that can be created on the fly (not in the mission editor) that accepts the Player being mounted. For my project I have a toboggan that appears under the player and the player is immediately mounted to it. But it could be a horse or a skateboard, for example.

You set up a keybind that sends a command to the server. On the server, create the new shape. In the shape's onAdd() script callback, mount the player to it -- you do this in onAdd() to ensure that the shape is in the server's scene graph prior to mounting. Also set the player to their sitting action animation.

Now on the client, run forwards and press the keybind to make the player mount the newly created shape. Rather than sitting on the mount, all clients will see that player in their root action animation.

Suggested Fix:
The problem ends up being that the client loses sync with the server when it comes to the mounted player. And the root cause of this is in Player::pickActionAnimation(). On the server, the player is mounted immediately and isMounted() will be true. On the client there is no guarentee that the newly created object to mount has come through prior to the Player's network update. So Player::pickActionAnimation() on the client the isMounted() check fails and continues to pick an action animation based on motion. This overrides any passed in action animation that came from the server for the mount.

Fortunately, the fix is simple. The client needs to check if there is a pending mount. Modify Player::pickActionAnimation as follows:

void Player::pickActionAnimation()
{
   // Only select animations in our normal move state.
   if (mState != MoveState || mDamageState != Enabled)
      return;

   // DAW: START
   // DAW: If there is a mount pending then we don't want to change the animation.
   //      A mount pending is when we're mounted, but the mount hasn't come through
   //      to the client just yet.
   //if (isMounted())
   if (isMounted() || mMountPending)
   // DAW: END
   {
      // Go into root position unless something was set explicitly
      // from a script.
      if (mActionAnimation.action != PlayerData::RootAnim &&
          mActionAnimation.action < PlayerData::NumTableActionAnims)
         setActionThread(PlayerData::RootAnim,true,false,false);
      return;
   }

You'll only notice this bug for a shape that has been specifically created at the moment of the mount. Such as a horse appearing at the player's position and the player immediately mounting it. This bug doesn't happen with objects that are already in the scene (such as being added with the Mission Editor) because they have already been synchronized with the client.

- Dave

About the author

A long time Associate of the GarageGames' community and author of the Torque 3D Game Development Cookbook. Buy it today from Packt Publishing!


#1
01/18/2011 (8:27 pm)
Logged as THREED-1348.
#2
04/24/2011 (5:46 pm)
Fixed in 1.1 Final and Preview.