movement of npc ships in freespace

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
madtulip
Halfling
Posts: 78
Joined: Thu Nov 18, 2004 6:35 pm

movement of npc ships in freespace

Post by madtulip »

im thinking about how to realise the movement for my enemy npc ships in my freespace application. my npc ship classe instances all have methodes

Code: Select all

void CShip::InjectMovement(int InjectedMovement)
{
	mInjectedMovement = InjectedMovement;
    switch (mInjectedMovement)
	{
		case 1:
			mfPitch -= 5.0;
			break;

		case 2:
			mfPitch += 5.0;
			break;
		case 3:
			mfRoll -= 5;
			break;
		case 4:
			mfRoll += 5;
			break;
		case 5:
			mfSpeed += mPhysikconst[2];
			if (mfSpeed > mPhysikconst[4])
				mfSpeed = mPhysikconst[4];
			break;
		case 6:
			mfSpeed -= mPhysikconst[3];
			if (mfSpeed < mPhysikconst[5])
				mfSpeed = mPhysikconst[5];
			break;
		case 7:
			mfAfterburner = mPhysikconst[1];
			break;
		case 8: // switch between 1st and 3rd person view
			if (mPlayerShip)
			{
				if (mbFirstPerson)
				{
					// third person
					mCameraNode->setPosition( Vector3( 0, 50, -200) );
					mbFirstPerson = false;
				}
				else
				{
					// first person
					mCameraNode->setPosition( Vector3( 0, 5, 40) );
					mbFirstPerson = true;
				}
			}
			break;
	}
}
via which i pass keyboard orders to the player ship i.e. i would like to use those further with the npc ships.

so about the ai. i thought there should be some "exact" methodes first, which are later on started from the random or cost based ai (the options a ship can choose from (i.e. chase target ship, try to face target, flee from target))

im currently trying to realiese this "exact methodes".

i.e. the player is behind the enemy. the enemy decieds to try to chase the player (get behind him).

i would create 3 planes trough the middle of the npc ship and would check if a spot behind the the target (the player) where the npc ship wants to position itself is above/below, left/right, front/rear relative to the npc ships position. then i would start the

npcship->InjectMovement(/*depending on whether the target(the player) is left right and so on*/);

if the player doesnt move, or if i recheck the planes every frame the npc ship should be possible to reach this spot behin the player ship sooner or later.but, if it reaches the spot, i would most certainly not face to back of the player, the npc ships orientation would be wrong, so the player would be in a bad angle for the npc ship to fire its weapons (which are mounted front).

that all wouldnt be the problem if my npc ships could move free into all 3 direction of the 3d space. but as they are aircraft like ships, they only accelerate into one direction(front).

i would need a routine that calculates what movement is to be injected now, to reach a destinatet point with a given orientation as soon as possible (based in its physical constants, that define the speed it can change its pitch / yaw / roll angles).

i read about bezier curves for camera flights. is that maybe a solution ?that would bring me away from my injectmovement methode. to simulate different ships, this physical constants that define the angle rotation speed around the 3 axis are important for me.

i thought that might be a mathematik problem others have dealed with allready. any advice, links or code ? thx for you time
madtulip
Halfling
Posts: 78
Joined: Thu Nov 18, 2004 6:35 pm

Post by madtulip »

isnt it so, that a bezier can be defined by starting and ending vector 3 and starting and ending orientaion and a 3 fixed change of degree per progress on the path constants ?

if i imagine a stick of wood, both edges in my hand. i could force it into a defined position when placing the edges in defined positions and orientations. at least if i define one further vector from one of my hands to the middle of the stick.

there must be a library for stuff like that, isnt it ?
madtulip
Halfling
Posts: 78
Joined: Thu Nov 18, 2004 6:35 pm

Post by madtulip »

http://danielh7.tripod.com/main/archive/bezier.txt

this creates a bezier patch from 4 points.

"
The path travels from Point 1 in the general direction of Point //
// 2, and arrives at Point 4 from the general direction of Point 3.
"
and i could transfor this to 3d also i guess - this is only for 2d. but the thing that still lacks is the angle rotation speed in all 3 direction which my ship have. to simulate more agile small ships and big ships that turn slower. even if they move with the same speed.

maybe its the wrong approach at all.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

Well, look at Ogre - it has bezier code in its belly.
And then there's the code behind the camera track demo .. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
madtulip
Halfling
Posts: 78
Joined: Thu Nov 18, 2004 6:35 pm

Post by madtulip »

thx for the hint. the camera track, animation and track seem to have all i need allready included.but i guess thats rather a grin but a smile - seems to be difficult. lets see what i can do :)