Okay - been playing around with your start for a while now and finally got to this. It doesn't look the same at all, but you can still see the basic concept is there.
Solutions:
Used 5 limbs (limb 0 + 4) for each basic direction (forward, up, down, left, and right).
Offset the limbs in their respective directions.
Get the distance from each limb to the target.
Determine the closest limb to the target.
Turn the missile object in the direction of the closest limb.
Move the missile forward.
Rinse and repeat.
Note: There are more functions than are used as I have a basic function include file I copy functions from as needed. I just copied the ones I might need and didn't bother to delete them if I didn`t use them.
Note: 100 missiles in this demo just to test speed.
Sync On:Sync Rate 60:Autocam Off
Type Coordinates
x as Float
y as Float
z as Float
EndType
Global Object as Coordinates
Global Target as Coordinates
Global AI as Coordinates
Global Camera As Coordinates
Global Limb As Coordinates
Clean_AI()
Make Mesh from Object 2,2
For i=101 to 200
Make Object Cube i,1
Scale Limb i,0,200,200,500
Restore Offsets
For j =1 to 4
Read lox#,loy#,loz#
Add Limb i,j,2
Offset Limb i,j,lox#,loy#,loz#
Next j
Position Object i,(i*2)-301,-5,0
Next i
Make Object Cube 3,20
Position Object 3,20,20,200
Do
For i = 101 to 200
AIM_Missile(i,3)
Move Object i,1
Next i
Move Object Down 3,Mousemovey()
Move Object Right 3,Mousemovex()
Move Object 3, Upkey()-Downkey()
Sync
Loop
Function Aim_Missile(ObjectID,TargetID)
md#=Squared_Distance(ObjectID,TargetID)+100
L=0
For i = 0 to 4
Set_AI_To_Limb(ObjectID,i)
nd#=Squared_Distance(2,TargetID)
If nd#<md#
L=i
md#=nd#
Endif
Next i
rn#=Rnd(100.0)/100.0
Select L
Case 0
`No Turning
Endcase
Case 1
Pitch Object Up ObjectID,1+rn#
EndCase
Case 2
Turn Object RIght ObjectID,1+rn#
EndCase
Case 3
Pitch Object Down ObjectID,1+rn#
EndCase
Case 4
Turn Object Left ObjectID,1+rn#
EndCase
EndSelect
EndFunction
` This function shortens the Object Postion X/Y/Z() functions.
Function Return_Object(ObjectID)
If Object Exist (ObjectID)
Object.x=Object Position X(ObjectID):Object.y=Object Position Y(ObjectID):Object.z=Object Position Z(ObjectID)
Endif
Endfunction
` This function shortens the Object Postion X/Y/Z() functions.
Function Return_Target(TargetID)
If Object Exist (TargetID)
Target.x=Object Position X(TargetID):Target.y=Object Position Y(TargetID):Target.z=Object Position Z(TargetID)
Endif
EndFunction
` This function shortens the Object Postion X/Y/Z() functions for object #2
Function Return_AI()
If Object Exist (2)
AI.x=Object Position X(2):AI.y=Object Position Y(2):AI.z=Object Position Z(2)
Endif
EndFunction
` This function shortens the Camera Postion X/Y/Z() functions.
Function Return_Camera()
Camera.x=Camera Position X():Camera.y=Camera Position Y():Camera.z=Camera Position Z()
EndFunction
` This function positions the AI object (#2) at ObjectID's position and set the AI to the ObjectID's orientation
Function Set_AI(ObjectID)
If Object Exist(ObjectID) And Object Exist(2)
Return_Object(ObjectID)
Position Object 2,Object.x,Object.y,Object.z
Set Object To Object Orientation 2,ObjectID
Endif
EndFunction
` This function deletes an old AI object and creates a new "clean" AI object.
Function Clean_AI()
If Object Exist(2) Then Delete Object 2
Make Object Sphere 2,1,6,6
Hide Object 2
Set Object Collision To Boxes 2
Set Object Collision Off 2
EndFunction
`This function places ObjectID at the AI position. It does not set the ObjectID's orientation
Function Set_Object(ObjectID)
If Object Exist(ObjectID)
If Object Exist(2)=0 Then Clean_AI()
Return_AI()
Position Object ObjectID,AI.x,AI.y,AI.z
Endif
EndFunction
`This function places the CameraID at the AI position. It does not orient the camera.
Function Set_Camera()
Return_AI()
Position Camera AI.x,AI.y,AI.z
EndFunction
`This function shortens the Limb Position X/Y/Z() functions
Function Return_Limb(ObjectID,LimbID)
If Object Exist(ObjectID)
If Limb Exist(ObjectID,LimbID)
Limb.x=Limb Position X(ObjectID,LimbID):Limb.y=Limb Position Y(ObjectID,LimbID):Limb.z=Limb Position Z(ObjectID,LimbID)
Endif
Endif
EndFunction
` This function positions the AI object (#2) at ObjectID's/LimbID's position and sets the AI orientation
Function Set_AI_to_Limb(ObjectID,LimbID)
If Object Exist(ObjectID)
If Limb Exist(ObjectID,LimbID)
If Object Exist(2)=0 Then Clean_AI()
Return_Limb(ObjectID,LimbID)
Position Object 2,Limb.x,Limb.y,Limb.z
Rotate Object 2,Limb Angle X(ObjectID,LimbID),Limb Angle Y(ObjectID,LimbID),Limb Angle Z(ObjectID,LimbID)
Endif
Endif
EndFunction
Function Squared_Distance(ObjectID,TargetID)
Return_Object(ObjectID)
Return_Target(TargetID)
dx#=Object.x-Target.x:dy#=Object.y-Target.y:dz#=Object.z-Target.z
d#=dx#*dx#+dy#*dy#+dz#*dz#
Endfunction d#
Offsets:
Data 0,1,-.2
Data 1,0,-.2
Data 0,-1,-.2
Data -1,0,-.2
Thanks Sven!
"Droids don't rip your arms off when they lose." -H. Solo
REALITY II