Game Development Community

How to make a flying vehicle copy the player?

by Lateral Punk · in Torque Game Engine · 09/19/2004 (1:10 pm) · 4 replies

Hi,
I have two planes, one the client player, and the other a flyingvehicle bot. The C++ code for the flyingvehicle bot was modified as described in www.garagegames.com/mg/forums/result.thread.php?qt=18851. I have read various postings on how to make a AI controlled flying vehicle, but none that specifically address my issue. Most of the approaches are based around a path, destination, or targeting another object. What i want is something even simpler than all that, and that is for the bot to "copy" the player jet, so that i can complete my task of a flying squadron doing various tricks. So whatever the player jet does, the bot mimics it. I have "somewhat" achived this by the following code:

//the the client controlled jet transform
	%xfrm = %this.client.player.getTransform();
	%clx = getword(%xfrm,0);
	%cly = getword(%xfrm,1);
	%clz = getword(%xfrm,2);
	%crx = getword(%xfrm,3);
	%cry = getword(%xfrm,4);
	%crz = getword(%xfrm,5);
	%crd = getword(%xfrm,6);
	
	for(%i = 0; %i < %this.numBots; %i++)
	{
		//get the bot transform
		%bot = %this.client.bot[%i];
		%bfrm = %bot.getTransform();
		%bx = getword(%bfrm,0);
		%by = getword(%bfrm,1);
		%bz = getword(%bfrm,2);
		//update the bot transform the match the client's transform
		%bot.schedule(100, "setTransform",	%clx SPC %cly SPC %clz SPC %crx SPC %cry SPC %crz SPC %crd);
	}

as you can see, this is very primitive by the fact that the client's transform is simply copied into the bot's transform. This somewhat works, but introduces the following problems:

1) jerkiness in the motion of the bot since the scheduled is called every 100ms. even reducing that number doesn't change the jerkiness.
2) the bot vehicle is just a dummy object now, it doesn't use any of the flying vehicle physics anymore.

So my question is, can someone describe a better approach to achieve my goal? any help is greatly appreciated.

thanks!

#1
09/19/2004 (7:06 pm)
I assume you are using a player with flying capabilities.

Try contacting Wendell Brown. He managed to create another AIvehicle approach that uses an AIconnection instead of AIPlayer. His bots do obey to flying vehicle physics.

HTH
#2
09/20/2004 (6:50 am)
I have already looked at Wendell's approach (both AIvehicle and AIconnection), and have actually used various aspects of them in my approach. But they still don't address my "exact copy" approach that i'm looking for. And Yes i am using a player with flying capabilities. I"m not overly concerned about the bot's flying vehicle physics as I am with them "exactly" mimicking the player's every move. And since the player's flying vehicle already observes proper physics, then so should the bots (if i can get them to copy what the player is doing, which is what my original quesiton is asking). Any more hints?

thanks
#3
09/20/2004 (7:20 am)
You could modify the C++ code to give them a reference to the player (youd have to get the ghost, see projectile.cc and mSourceObject for specifics) . Then add a method to the player that returns the last recieved move stucture.

Then call that getMove method in the dummy jets processTick method... I suppose that might work.
#4
09/20/2004 (7:51 am)
Actually I kinda just did something like this via scripting. What i do is whenver the user presses key that is related to their plane movement, i send that same information to the bots. This actually is achieving my goal of the bots copying the player. Here is how i do it:
function Game3::playerAction(%this,%action)
{
	for(%i = 0; %i < %this.numBots; %i++)
	{
		%bot = %this.client.bot[%i];

		 if (%bot.neutralize_id != -1)
		 cancel(%bot.neutralize_id);

		switch$(%action)
		{
			 case "neutral":
			 %bot.neutralize();
			 case "right":
			 %bot.setYaw(0.2);
			 case "left":
			 %bot.setYaw(-0.2);
			 case "pull":
			 %bot.setPitch(-0.4);
			 %bot.neutralize_id = %bot.schedule(1500, "neutralize");
			 case "push":
			 %bot.setPitch(0.4);
			 %bot.neutralize_id = %bot.schedule(1500, "neutralize");
		case "high":
			%bot.setAiThrust(1);
		case "med":
			%bot.setAiThrust(0.66);
		case "low":
			%bot.setAiThrust(0.33);
		}
	}

}

unfortunately, this is working to perfectly!! let me explain myself, i got a squadron of planes, with the lead plane being the player. The player is to do tricks, which the bots mimic. Now the player's plane should always be in the front, and the bots follow it. but with my current implementaiton, when the player goes and does a a loop, at the end of the loop, the player ends up behind the bots, and not in front. And this makes perfect sense according to the way i have implemetned it by the above code, but its not what i want. Also what i require is that if the player does a pitch to the left, then all the bots to its left, move down, and all the bots to its right move up. but instead right now i have the bots doing exactly what the client is doing (well that's what i asked for originally anways :) I'm going to tweak it a little further, but any help according to my approach would be great.