Elite NPC movement

Blitz3D Forums/Blitz3D Programming/Elite NPC movement

*(Posted 2005) [#1]
Anyone have any ideas on how to do the roll to required angle then pitch to face target thingy that the NPC's do in Elite?

Ive been wracking me brain trying to work this one out to no great success. I can get the ships to face thier target but without rolling and pitching which I want as its homage to Elite :).

Any ideas as triganometry isnt my strong point nor is quaterions etc.


_PJ_(Posted 2005) [#2]
What's required, is for the AI ships' movement to be limited to just pitching and rolling. Then, ensure the only thrust will be from behind the craft.

Use TFormPoint and some pivots placed LOCALLY ABOVE & BELOW the ai craft to work out the correct angle required so the roll places the target craft LOCALLY VERTICAL* from the AI craft. Then, pitch the craft until it faces the target.

*Hope this makes sense.


*(Posted 2005) [#3]
thanks will have a look, if anyone has a code example it would be appreciated ;)


*(Posted 2005) [#4]
If anyone has a code example it would be appreciated ;). I need the roll so I know what to roll the entity to the desired angle so that when it pitches it faces its quarry.


KuRiX(Posted 2005) [#5]
I think i don't understand quite well what you need but:

Pointentity enta,entb,rollangle#

could help you...


Jeremy Alessi(Posted 2005) [#6]
You mean you just want the ships to have the same roll so neither is upside down relative to the other? Makes sense to me that you'd adjust the roll of the targeting ship to match the target's roll and then you'd use:

DeltaPitch(ship, target) 


to get the pitch the ship should be at to be facing the target and slowly adjust it's pitch until DeltaPitch equals zero.


*(Posted 2005) [#7]
In Elite all NPC's roll first to an angle that places thier target in place so all they have to do is pitch up or down to get them in line to shoot at. They never roll along all axis its always roll first then pitch up or down.

What im trying to work out is the roll angle required to roll the ship so they are on the pitching line.


Jeremy Alessi(Posted 2005) [#8]
Um ... I mean you could always pitch to face a ship no matter what the roll is ... it's more yaw that would matter not roll I would think. Still you could do a combo yaw and roll. Use DeltaYaw and also roll the ship simultaneously so that it's roll is right side up relative to the target and then use DeltaPitch. I wish I had ever played Elite so I could see what you're talking about because it's not making a whole lot of sense right now. Nevertheless, DeltaYaw and DeltaPitch are your friends I'm sure.


Matty(Posted 2005) [#9]
3 Vectors:

AI Ship's forwards vector =A
AI Ship's "up" vector =B
Vector of line from AI Ship to AI target ship. = C

Cross product of A & C should have the same direction (but not magnitude so convert the results to unit vectors) as the Cross product of B & C if I am understanding you correctly when the ship has rolled to its correct position.

Vector A does not change while rolling.
So you want to roll the craft until the direction of the vector A x C equals the direction of the vector B x C

So:
Calculate A x C and convert the resulting vector to a unit vector (ie length of 1).

Calculate B x C and convert it to a unit vector as well.
Roll the craft and check again.

When the difference between these two resulting unit vectors is small then you have gotten pretty darn close to having the correct roll and you can then start pitching.


Viperfish(Posted 2005) [#10]
;Determine targetleaders x,y,z location relative to the enemy ship
			EntityParent TargetLeader,e\entity
			TargetX# = EntityX(TargetLeader,False)
			TargetY# = EntityY(TargetLeader,False)
			TargetZ# = EntityZ(TargetLeader,False)
			EntityParent TargetLeader,pvt
			;--------------------------
			;Calculate Steering factor. The further away an entity is the higher the factor
			SteeringFactor# = EntityDistance(TargetLeader,e\entity)/1000
			
			;--------------------------
			;Rotate z based on x position (Roll the ship so target is near vertical axis)
			If targetX < -30*(SteeringFactor#-RandomFactor#) 
				If TargetY < 0 ;Below and to the left, turn right
					e\roll# = e\roll# -(e\spz/TurningFactor%)
				Else
				 	e\roll# = e\roll# +(e\spz/TurningFactor%);Above and to the left, roll left
				End If
			End If
			If TargetX > 30*SteeringFactor# 
				If TargetY > 0;Above And To the Right, turn Right
					e\roll# = e\roll# -(e\spz/TurningFactor%)
				Else 
					e\roll# = e\roll# +(e\spz/TurningFactor%);Below and to the right, turn left
				End If
			End If
			
			;--------------------------
			;Rotate x based on y (Climb or dive to face the target only if the target is near the 
			;vertical axis). Climb is the target is behind.
			If TargetZ < 0 Then 
				e\pitch# = e\pitch# - (e\spx/TurningFactor%)
			Else
				If Abs(TargetX) <(100* (SteeringFactor#-RandomFactor#)) Then
					If TargetY > 30*SteeringFactor# Then
						e\pitch# = e\pitch# - (e\spx/TurningFactor%)
					End If
					If TargetY < -30*SteeringFactor# Then
						e\pitch# = e\pitch# + (e\spx/TurningFactor%)
					End If				
				End If
			End If
		;************* TURN AND MOVE THE SHIP  **********************************	
		
		;Rotate z based on roll position so craft flies horizontal
			If Abs(e\roll)<0.1 And Abs(e\pitch)<0.1 Then
				If EntityRoll(e\entity) < -5 
					;e\roll# = e\roll# +(e\spz/TurningFactor%)
					TurnEntity e\entity,0,0,(e\spz/TurningFactor%)
				End If
				If EntityRoll(e\entity) > 5 
					;e\roll# = e\roll# -(e\spz/TurningFactor%)
					TurnEntity e\entity,0,0,-(e\spz/TurningFactor%)
				End If	
			End If

		e\pitch = e\pitch/1.1
		e\roll = e\roll/1.1
		e\yaw = e\yaw/1.1
		TurnEntity e\entity,e\pitch#*FL\SpeedFactor,e\yaw#*FL\SpeedFactor,e\roll#*FL\SpeedFactor
		MoveEntity e\entity, 0, 0 ,e\spd*FL\SpeedFactor
		;--------------------------




This is a small snippet of code from the AI function in my current project TRAFFIKA. It is also based on Elite and is coming along fantastically well.
It basically rolls the ship until the target is relatively vertical then pitches until it is infront. There are many other parts to this function to speed up, slow down, dodge, etc. But, I think this is the sort of thing you were after.

You can download a working copy of the game so far at http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=bigjohnno03142005145609&comments=no. It's about 40% complete and has come along way since I posted it. Check it out and let me know how you get along.

Oh, a few things to note;
e\entity - enemy entity
e\roll - enemy's roll
e\pitch - enemy's pitch
e\spx - enemy's climb speed
e\spz - enemy's pitch speed
e\randomfactor - random number to give each ship slightly different action. It is very noticable when groups of 5 or more are flying together.
e\targetleader - distanceof a pivot infront of the target which the enemy aims at. If it aims at the target it never hits it because its moving. e\targetleader is recalculated every round by taking into acount distances and speeds.


*(Posted 2005) [#11]
thanks will have a look :)