Game Development Community

dev|Pro Game Development Curriculum

AFX Selected Objects, AutoAttack AI and Jerkiness.

by Danni · 07/16/2008 (6:23 pm) · 4 comments

I made the leap and bought AFX to checkout the coolness of this wonderful resource. Immediately i thought what cool this would be to use AFX to create weapon effects or even summoned weapons (www.youtube.com/watch?v=zLpLoLGdack&hl=en). That's when I found the cool AFXWeapon resource from Michael Perry, a good starting point and even has a stats class with it, shouldn't take long to mold this the way i want it. But first! How to go about actually handling the battles. Well spells are simple, just cast from a distance, but what about normal attacks.

I decided on implementing an AI method to control the player and target and bring them together to hash out the damage. Lets cheat here and use AFX's selectobj system and a spinoff from getAIMove. Strange, AFX's getSelectedObj() is NULL, how can that be?! I clearly have a player selected, there is netcode here to transfer the selected object, whats up?! Oh wait.. that's sending it server to client but the selection is client side. Weird!? Not a problem... (Hack, hack, hack).

Under mMoveList.serverReadMovePacket(bstream);
mMoveList.serverReadMovePacket(bstream);
	  
[b]	  // [Danni] Retreive and resolve selected client object.
	  if(bstream->readFlag())
	  {
		  if(bstream->readFlag())
		  {
		     S32 gIndex = bstream->readInt(NetConnection::GhostIdBitSize);
             setSelectedObj(static_cast<SceneObject*>(resolveObjectFromGhostIndex(gIndex)));
		  }
		  else
		  {
		     setSelectedObj(NULL);
		  }
	  }[/b]

      mCameraPos = bstream->readFlag() ? 1.0f : 0.0f;

Then under mMoveList.clientWriteMovePacket(bstream);
mMoveList.clientWriteMovePacket(bstream);

		[b]// [Danni] Send selected object to server
		if (bstream->writeFlag(mChangedClientSelectedObj))
		{
			mChangedClientSelectedObj = false;
			S32 gidx;
			if (mSelectedObj && !mSelectedObj.isNull() && (gidx = getGhostIndex(mSelectedObj)) != -1)
		 {
			 bstream->writeFlag(true);
			 bstream->writeInt(gidx, NetConnection::GhostIdBitSize);
		 }
			else
			{
				bstream->writeFlag(false);
			}
		}[/b]

		bstream->writeFlag(mCameraPos == 0);

Problem solved! Here is a nice video of the result antihax.net/movies/AFXAutomoves.wmv Now to interpolate out that nasty jerkiness and free the camera's rotation. May not notice but I already freed the camera height.

#1
07/17/2008 (12:13 am)
Quote:even summoned weapons (www.youtube.com/watch?v=zLpLoLGdack&hl=en).

Now THAT'S a big F**kin' sword!

Keep us updated on your AFX experiences. It always seems someone buys it, makes a bunch of "OH WOW!" posts for the first weeks, then disappears... I'd like to hear from long-term users of AFX and get an idea of the shiny new toy is still shiny several months later...
#2
07/17/2008 (8:40 am)
Never seen a better use of Lina Inverse on a blog post!
#3
07/17/2008 (1:43 pm)
Very nice. I've been struggling myself getting a 'mountVehicle' command to accept the afx client selected object as the serverID'd input. No form of ghostID, etc commands would produce the value I required. This really looks like what I needed!
#4
07/17/2008 (3:14 pm)
Erik: I hope it helps, don't forget to add bool mChangedClientSelectedObj to the Player class and set it false in the constructor.

Dave: Oldie but a goodie. :)

Brian: I doubt I will get anything complete worth great celebration, I am mostly learning more about the engine and systems in general. Since most of the time I find someone else who is after similar things I try to share anything I find. :)