What's wrong with my Hockey code???

Blitz3D Forums/Blitz3D Programming/What's wrong with my Hockey code???

D_Town_Tony(Posted 2004) [#1]
I've taken some time off from my main project to see if I could create a quick Hockey game.

The problem that I am having is that when you pass the puck it'll go to the closest target, but after the new "character"(it's just a box right now) has control. When I try to pass it again it goes in some odd direction, but if you pick up the puck again and pass it, it suddenlt works. Here's the code in this .zip any help would be greatly appreciated.

http://www.sideways8-games.com/files/hockey_engine.zip

please help


D_Town_Tony(Posted 2004) [#2]
Here's the code in a simpler form. I'm at my wits end
with this...can someone please take a look.

Graphics3D 800,600,0
SetBuffer BackBuffer()
WBuffer False

Global light
Global gravity#=-0.04

Global puck_under_control,puck_under_control_player_num

;Player 1
Global Player_1_UP=200
Global Player_1_Down=208
Global Player_1_Left=203
Global Player_1_Right=205
Global Player_1_Shoot=54
Global Player_1_Pass=157

Const player_1_col=1
Const world_col=3
Const Puck_col=4

Collisions player_1_col,world_col,2,2
Collisions Puck_col,world_col,2,2

Global Main_Camera_1=CreateCamera()
MoveEntity Main_Camera_1,0,125,-150
TurnEntity Main_Camera_1,50,0,0
CameraZoom Main_Camera_1,1.5

Type ball
Field e ;entity
Field sphere
Field pivot
Field x#,y#,z# ; position in 3d-space
Field vx#,vy#,vz# ; velocity
Field ax#,ay#,az# ; acceleration
Field bounce# ; bounce factor
Field vel#
Field vx2#,vy2#,vz2# ; temp velocity
End Type

Global puck_shot,pass_1,pass_2,pass_3

Global Player_1_Under_Control=1
Global Pass_Target=CreateCube()

ScaleEntity Pass_Target,3,3,3
EntityAlpha Pass_Target,.5
EntityColor Pass_Target,0,10,255

Type Team_1_P1
	Field entity ;entity
	Field t1x#,t1y#,t1z# ; position in 3d-space
	Field t1vx#,t1vy#,t1vz# ; velocity
	Field t1ax#,t1ay#,t1az# ; acceleration
	Field speed#,maxspeed#
	Field stick_Pivot,stick_pivot_aim
	Field Player_Number
	Field passed_puck
	Field aimer
End Type

Type Team_1_P2
	Field entity ;entity
	Field t1x#,t1y#,t1z# ; position in 3d-space
	Field t1vx#,t1vy#,t1vz# ; velocity
	Field t1ax#,t1ay#,t1az# ; acceleration
	Field speed#,maxspeed#
	Field stick_Pivot,stick_pivot_aim
	Field Player_Number
	Field passed_puck
	Field aimer
End Type

Setup_rink()
Create_Player1(0,20,0)
Create_Player2(75,20,-40)
create_puck(0,4,-120,0.8)

While Not KeyHit(1)
Sort_Distance()
Player1_update()
Player1_control()
update_Camera()
puck_control_update()
If puck_shot>0 Then puck_shot=puck_shot-1

If puck_under_control=0
  ballupdate()
EndIf
ballcontrol()

If puck_under_control=1
If puck_shot=0 UpdateWorld
EndIf

;UpdateWorld is in ballupdate	
RenderWorld
Flip
Wend
End


Function Setup_rink()
  light=CreateLight()
  ice=CreateCube()
  ScaleEntity ice,400,1,300
  EntityColor ice,255,255,255
  EntityType ice,3
  EntityAlpha ice,.5
  EntityFX ice,1
  reflection=CreateMirror(ice)

  cube=CreateCube()
  FitMesh cube,-400,0,200,800,50,200
  EntityType cube,3
  EntityColor cube,50,100,225


  pass_1=CreateCylinder()
  ScaleMesh pass_1,2,3.5,2
  PositionEntity pass_1,75,4,-20
  EntityColor pass_1,255,50,50

  pass_2=CreateCylinder()
  ScaleMesh pass_2,2,3.5,2
  PositionEntity pass_2,-85,4,30
  EntityColor pass_2,255,255,50
End Function




Function puck_control_update()
	For c.ball=Each ball
	;T1_P2
	  For T1_P1.Team_1_P1=Each Team_1_P1
	  If puck_under_control=0
	     If puck_shot=0
	     If T1_P1\passed_puck=0
	     If EntityDistance(T1_P1\stick_pivot,c\sphere)<6 
	       puck_under_control=1
	       puck_under_control_player_num=1
	       Player_1_Under_Control=1
				  TFormVector 0,0,0,T1_P1\aimer,0
	     EndIf
	     EndIf
         EndIf
	  EndIf
      If puck_under_control=1 And puck_under_control_player_num=1
         EntityParent c\sphere,T1_P1\stick_pivot
         PositionEntity c\sphere,0,0,0
         EntityParent c\e,T1_P1\stick_pivot
         PositionEntity c\e,0,0,0 
         EntityParent c\pivot,T1_P1\stick_pivot
         PositionEntity c\pivot,0,0,0
      EndIf
	  Next
	;T1_P2
	  For T1_P2.Team_1_P2=Each Team_1_P2
	  If puck_under_control=0
	     If puck_shot=0
	     If T1_P2\passed_puck=0
	     If EntityDistance(T1_P2\stick_pivot,c\sphere)<6 
	       puck_under_control=1
	       puck_under_control_player_num=2
	       Player_1_Under_Control=2
					  TFormVector 0,0,0,T1_P2\aimer,0
	     EndIf
	     EndIf
         EndIf
	  EndIf
      If puck_under_control=1 And puck_under_control_player_num=2
         EntityParent c\sphere,T1_P2\stick_pivot
         PositionEntity c\sphere,0,0,0
         EntityParent c\e,T1_P2\stick_pivot
         PositionEntity c\e,0,0,0 
         EntityParent c\pivot,T1_P2\stick_pivot
         PositionEntity c\pivot,0,0,0
      EndIf
	  Next
	Next
End Function

Function create_puck(x#,y#,z#,bounce#=0.9)	
	c.ball=New ball	
	c\x#=x#
	c\y#=y#
	c\z#=z#	
	c\bounce#=bounce#	
	c\e=CreatePivot()
	c\sphere=CreateCylinder()	
	c\pivot=CreatePivot()	
	EntityType c\e,Puck_col
	EntityRadius c\e,.15	
	PositionEntity c\e,c\x,c\y,c\z
	ScaleEntity c\sphere,1,.5,1
	EntityColor c\sphere,30,30,30
End Function

Function ballupdate()
	For c.ball=Each ball		
		c\vy#=c\vy#+gravity#
		
		c\vx#=c\vx#+c\ax#
		c\vy#=c\vy#+c\ay#
		c\vz#=c\vz#+c\az#
		
		c\x#=EntityX(c\e)
		c\y#=EntityY(c\e)
		c\z#=EntityZ(c\e)	
		TranslateEntity c\e,c\vx,c\vy,c\vz	
	Next
	UpdateWorld()	
For c.ball=Each ball
		;correct velocity if collided
		c\vx2=(EntityX(c\e)-c\x)
		c\vy2=(EntityY(c\e)-c\y)
		c\vz2=(EntityZ(c\e)-c\z)	
		c\x#=EntityX(c\e)
		c\y#=EntityY(c\e)
		c\z#=EntityZ(c\e)	
		PositionEntity c\sphere,c\x,c\y,c\z
		PositionEntity c\pivot,c\x,c\y,c\z
;collide_with world	
		If EntityCollided(c\e,world_col)			
			For i = 1 To CountCollisions(c\e)
				; Get the normal of the surface which the entity collided with. 
				Nx# = CollisionNX(c\e, i) 
				Ny# = CollisionNY(c\e, i) 
				Nz# = CollisionNZ(c\e, i) 			
				; Compute the dot product of the entity's motion vector and the normal of the surface collided with. 
				VdotN# = c\vx#*Nx# + c\vy#*Ny# + c\vz#*Nz# 				
				; Calculate the normal force. 
				NFx# = -2.0 * Nx# * VdotN# 
				NFy# = -2.0 * Ny# * VdotN# 
				NFz# = -2.0 * Nz# * VdotN# 				
				; Add the normal force to the direction vector. 
				c\vx# = c\vx# + NFx# * c\bounce#
				c\vy# = c\vy# + NFy# * c\bounce#
				c\vz# = c\vz# + NFz# * c\bounce#
				avx#=EntityPitch(c\sphere)
				avy#=EntityYaw(c\sphere)
				avz#=EntityRoll(c\sphere)
				;Rotate stuff
				;Get vector from center to collision
				dx1#=(CollisionX(c\e,i)-c\x)
				dy1#=(CollisionY(c\e,i)-c\y)
				dz1#=(CollisionZ(c\e,i)-c\z)
				dx2#=c\vx
				dy2#=c\vy
				dz2#=c\vz
				;Cross product
				cx# = ( dy1 * dz2 ) - ( dz1 * dy2 ) 
				cy# = ( dz1 * dx2 ) - ( dx1 * dz2 ) 
				cz# = ( dx1 * dy2 ) - ( dy1 * dx2 ) 															
				AlignToVector c\pivot,cx,cy,cz,1																						
			Next
			Nx# = CollisionNX(c\e, 1) 
			Ny# = CollisionNY(c\e, 1) 
			Nz# = CollisionNZ(c\e, 1) 				
			AlignToVector c\e,Nx#,Ny#,Nz#,2,0.5			
			c\vel#=Sqr(c\vx2*c\vx2+c\vy2*c\vy2+c\vz2*c\vz2)						
			;slow down due to friction
			c\vx#=c\vx*0.98
			c\vy#=c\vy*0.98
			c\vz#=c\vz*0.98
		EndIf	
		EntityParent c\sphere,c\pivot								
		EntityParent c\sphere,0
		c\ax#=0
		c\ay#=0
		c\az#=0			
	Next	
End Function


Function ballcontrol()
	For c.ball=Each ball
	If puck_under_control=1
	    ;SHOOT DA PUCK!!!!!!!!!!!!!!!!!!!!!!
		If KeyHit(Player_1_Shoot)
		  For T1_P1.Team_1_P1=Each Team_1_P1
		  If puck_under_control_player_num=1 PointEntity c\e,T1_P1\stick_pivot_aim
		  Next
		  For T1_P2.Team_1_P2=Each Team_1_P2
		  If puck_under_control_player_num=2 PointEntity c\e,T1_P2\stick_pivot_aim
		  Next
		    puck_under_control=0
		    puck_under_control_player_num=0
		    EntityParent c\sphere,0
		    EntityParent c\e,0
	        EntityParent c\pivot,0
		    If puck_shot=0
			TFormVector 0,2,5,c\e,0		
			c\ax#=TFormedX()
			c\ay#=TFormedY()
			c\az#=TFormedZ()
			EndIf
			puck_shot=5		
		EndIf	
		
		;PASS DA PUCK!!!!!!!!!!!!!!!!!!!!
		If KeyHit(Player_1_Pass)  
		;==================player_1_Pass
		If puck_under_control_player_num=1
		For T1_P1.Team_1_P1=Each Team_1_P1
		    RotateEntity c\e,0,EntityYaw(T1_P1\aimer),0,True
            value_3#=EntityYaw(T1_P1\aimer)
            value_4#=EntityYaw(c\e,True)
			  puck_under_control=0
		      puck_under_control_player_num=0
	
		      EntityParent c\sphere,0
		      EntityParent c\e,0
	          EntityParent c\pivot,0

			  TFormVector 0,0,EntityDistance(c\e,Pass_Target)*.035,T1_P1\aimer,0

			c\ax#=TFormedX()
			c\ay#=TFormedY()
			c\az#=TFormedZ()
			
			  T1_P1\passed_puck=20	
			  puck_shot=5	

		Next
		EndIf
		;================end Player_1_Pass
		;==================player_2_Pass
		If puck_under_control_player_num=2
		For T1_P2.Team_1_P2=Each Team_1_P2
		    RotateEntity c\e,0,EntityYaw(T1_P2\aimer),0,True
            value_3#=EntityYaw(T1_P2\aimer)
            value_4#=EntityYaw(c\e,True)
			  puck_under_control=0
		      puck_under_control_player_num=0
	
		      EntityParent c\sphere,0
		      EntityParent c\e,0
	          EntityParent c\pivot,0

			  TFormVector 0,0,EntityDistance(c\e,Pass_Target)*.035,T1_P2\aimer,0

			c\ax#=TFormedX()
			c\ay#=TFormedY()
			c\az#=TFormedZ()
			
			  T1_P2\passed_puck=20	
			  puck_shot=5	

		Next
		EndIf
		;================end Player_2_Pass
		EndIf
	EndIf
	Next
End Function


Function update_Camera()
For c.ball=Each ball
PositionEntity 	Main_Camera_1,EntityX(c\e,True),155,EntityZ(c\e,True)-100
Next
End Function

Function Create_Player1(xpos#,ypos#,zpos#)
  T1_P1.Team_1_P1 = New Team_1_P1
  T1_P1\t1x#=xpos# : T1_P1\t1y#=ypos# :T1_P1\t1z#=zpos#
  T1_P1\entity=CreateCube()
  ScaleEntity T1_P1\entity,2,2,2 
  EntityType T1_P1\entity,1
  PositionEntity T1_P1\entity,T1_P1\t1x#,T1_P1\t1y#,T1_P1\t1z#
  EntityRadius T1_P1\entity,2,2
  T1_P1\maxspeed#=.2
  T1_P1\stick_pivot=CreateCube(T1_P1\entity)
  MoveEntity T1_P1\stick_pivot,1,-1,1
  ScaleEntity T1_P1\stick_pivot,.25,.25,.25
  EntityColor T1_P1\stick_pivot,200,150,125
  T1_P1\stick_pivot_aim=CreateCube(T1_P1\entity)
  MoveEntity T1_P1\stick_pivot_aim,1,-1,10
  ScaleEntity T1_P1\stick_pivot_aim,.25,.25,.25
  EntityColor T1_P1\stick_pivot_aim,255,100,100
  T1_P1\aimer=CreateCube()
  T1_P1\Player_Number=1
End Function

Function Create_Player2(xpos#,ypos#,zpos#)
  T1_P2.Team_1_P2 = New Team_1_P2
  T1_P2\t1x#=xpos# : T1_P2\t1y#=ypos# :T1_P2\t1z#=zpos#
  T1_P2\entity=CreateCube()
  EntityColor T1_P2\entity,100,255,100
  ScaleEntity T1_P2\entity,2,2,2 
  EntityType T1_P2\entity,1
  PositionEntity T1_P2\entity,T1_P2\t1x#,T1_P2\t1y#,T1_P2\t1z#
  EntityRadius T1_P2\entity,2,2
  T1_P2\maxspeed#=.2
  T1_P2\stick_pivot=CreateCube(T1_P2\entity)
  MoveEntity T1_P2\stick_pivot,1,-1,1
  ScaleEntity T1_P2\stick_pivot,.25,.25,.25
  EntityColor T1_P2\stick_pivot,200,150,125
  T1_P2\stick_pivot_aim=CreateCube(T1_P2\entity)
  MoveEntity T1_P2\stick_pivot_aim,1,-1,10
  ScaleEntity T1_P2\stick_pivot_aim,.25,.25,.25
  EntityColor T1_P2\stick_pivot_aim,255,100,100
  T1_P2\aimer=CreateCube()
  T1_P2\Player_Number=2
End Function

Function Player1_update()
    ;player 1
	For T1_P1.Team_1_P1=Each Team_1_P1
	PointEntity T1_P1\aimer,Pass_Target
		T1_P1\t1vy#=T1_P1\t1vy#+gravity#
			
		T1_P1\t1vx#=T1_P1\t1vx#+T1_P1\t1ax#
		T1_P1\t1vy#=T1_P1\t1vy#+T1_P1\t1ay#
		T1_P1\t1vz#=T1_P1\t1vz#+T1_P1\t1az#
			
		T1_P1\t1x#=EntityX(T1_P1\entity)
		T1_P1\t1y#=EntityY(T1_P1\entity)
		T1_P1\t1z#=EntityZ(T1_P1\entity)	
		TranslateEntity T1_P1\entity,T1_P1\t1vx,T1_P1\t1vy,T1_P1\t1vz
		If T1_P1\passed_puck>0 Then T1_P1\passed_puck=T1_P1\passed_puck-1
		PositionEntity T1_P1\aimer,EntityX(T1_P1\stick_pivot,True),EntityY(T1_P1\stick_pivot,True),EntityZ(T1_P1\stick_pivot,True)
	Next	
	For T1_P1.Team_1_P1=Each Team_1_P1	
		;correct velocity if collided
		T1_P1\t1vx=(EntityX(T1_P1\entity)-T1_P1\t1x)
		T1_P1\t1vy=(EntityY(T1_P1\entity)-T1_P1\t1y)
		T1_P1\t1vz=(EntityZ(T1_P1\entity)-T1_P1\t1z)	
		;slow down due to friction
		If EntityCollided(T1_P1\entity,world_col)		
			T1_P1\t1vx#=T1_P1\t1vx*0.98
			T1_P1\t1vy#=T1_P1\t1vy*0.98
			T1_P1\t1vz#=T1_P1\t1vz*0.98	
		EndIf	
		T1_P1\t1ax#=0
		T1_P1\t1ay#=0
		T1_P1\t1az#=0
	Next	
	;player 2	
	For T1_P2.Team_1_P2=Each Team_1_P2
		PointEntity T1_P2\aimer,Pass_Target
		T1_P2\t1vy#=T1_P2\t1vy#+gravity#
			
		T1_P2\t1vx#=T1_P2\t1vx#+T1_P2\t1ax#
		T1_P2\t1vy#=T1_P2\t1vy#+T1_P2\t1ay#
		T1_P2\t1vz#=T1_P2\t1vz#+T1_P2\t1az#
			
		T1_P2\t1x#=EntityX(T1_P2\entity)
		T1_P2\t1y#=EntityY(T1_P2\entity)
		T1_P2\t1z#=EntityZ(T1_P2\entity)	
		TranslateEntity T1_P2\entity,T1_P2\t1vx,T1_P2\t1vy,T1_P2\t1vz
		If T1_P2\passed_puck>0 Then T1_P2\passed_puck=T1_P2\passed_puck-1
		PositionEntity T1_P2\aimer,EntityX(T1_P2\stick_pivot,True),EntityY(T1_P2\stick_pivot,True),EntityZ(T1_P2\stick_pivot,True)
	Next	
	For T1_P2.Team_1_P2=Each Team_1_P2	
		;correct velocity if collided
		T1_P2\t1vx=(EntityX(T1_P2\entity)-T1_P2\t1x)
		T1_P2\t1vy=(EntityY(T1_P2\entity)-T1_P2\t1y)
		T1_P2\t1vz=(EntityZ(T1_P2\entity)-T1_P2\t1z)	
		;slow down due to friction
		If EntityCollided(T1_P2\entity,world_col)		
			T1_P2\t1vx#=T1_P2\t1vx*0.98
			T1_P2\t1vy#=T1_P2\t1vy*0.98
			T1_P2\t1vz#=T1_P2\t1vz*0.98	
		EndIf	
		T1_P2\t1ax#=0
		T1_P2\t1ay#=0
		T1_P2\t1az#=0
	Next	
	
;puck_aim
End Function

Function Player1_control()
If Player_1_Under_Control=1
	For T1_P1.Team_1_P1=Each Team_1_P1
		If KeyDown(Player_1_UP)		
			TFormVector 0,0,0.02,T1_P1\entity,0	
			T1_P1\t1ax#=TFormedX()
			T1_P1\t1ay#=TFormedY()
			T1_P1\t1az#=TFormedZ()
		EndIf
		If KeyDown(Player_1_Down)
		    If T1_P1\t1vx > 0 And T1_P1\t1vy > 0 And T1_P1\t1vz > 0
			T1_P1\t1vx=T1_P1\t1vx*0.97
			T1_P1\t1vy=T1_P1\t1vy*0.97
			T1_P1\t1vz=T1_P1\t1vz*0.97	
		    Else	
		    TFormVector 0,0,-0.01,T1_P1\entity,0	
			T1_P1\t1ax#=TFormedX()
			T1_P1\t1ay#=TFormedY()
			T1_P1\t1az#=TFormedZ()
			EndIf
		EndIf
		If KeyDown(57)	
			TFormVector 0,0.05,0,T1_P1\entity,0
			T1_P1\t1ax#=T1_P1\t1ax+TFormedX()
			T1_P1\t1ay#=T1_P1\t1ay+TFormedY()
			T1_P1\t1az#=T1_P1\t1az+TFormedZ()							
		EndIf
		If KeyDown(Player_1_Left)	
			TurnEntity T1_P1\entity,0,3,0		
    	EndIf
		If KeyDown(Player_1_Right)	
			TurnEntity T1_P1\entity,0,-3,0		
		EndIf	
		
		;additional speed
		MoveEntity T1_P1\entity,0,0,T1_P1\speed#
	    If KeyDown(Player_1_UP)	
			If T1_P1\speed#<T1_P1\maxspeed# Then T1_P1\speed#=T1_P1\speed#+.01
		EndIf
		If Not KeyDown(Player_1_UP) 
		    If T1_P1\speed#>0 Then T1_P1\speed#=T1_P1\speed#-.0005
		EndIf
		If T1_P1\speed#<0 Then T1_P1\speed#=0
		If KeyDown(Player_1_DOWN) Then T1_P1\speed#=T1_P1\speed#-.01
	Next
EndIf

If Player_1_Under_Control=2
	For T1_P2.Team_1_P2=Each Team_1_P2
		If KeyDown(Player_1_UP)		
			TFormVector 0,0,0.02,T1_P2\entity,0	
			T1_P2\t1ax#=TFormedX()
			T1_P2\t1ay#=TFormedY()
			T1_P2\t1az#=TFormedZ()
		EndIf
		If KeyDown(Player_1_Down)
		    If T1_P2\t1vx > 0 And T1_P2\t1vy > 0 And T1_P2\t1vz > 0
			T1_P2\t1vx=T1_P2\t1vx*0.97
			T1_P2\t1vy=T1_P2\t1vy*0.97
			T1_P2\t1vz=T1_P2\t1vz*0.97	
		    Else	
		    TFormVector 0,0,-0.01,T1_P2\entity,0	
			T1_P2\t1ax#=TFormedX()
			T1_P2\t1ay#=TFormedY()
			T1_P2\t1az#=TFormedZ()
			EndIf
		EndIf
		If KeyDown(57)	
			TFormVector 0,0.05,0,T1_P2\entity,0
			T1_P2\t1ax#=T1_P2\t1ax+TFormedX()
			T1_P2\t1ay#=T1_P2\t1ay+TFormedY()
			T1_P2\t1az#=T1_P2\t1az+TFormedZ()							
		EndIf
		If KeyDown(Player_1_Left)	
			TurnEntity T1_P2\entity,0,3,0		
    	EndIf
		If KeyDown(Player_1_Right)	
			TurnEntity T1_P2\entity,0,-3,0		
		EndIf	
		
		;additional speed
		MoveEntity T1_P2\entity,0,0,T1_P2\speed#
	    If KeyDown(Player_1_UP)	
			If T1_P2\speed#<T1_P2\maxspeed# Then T1_P2\speed#=T1_P2\speed#+.01
		EndIf
		If Not KeyDown(Player_1_UP) 
		    If T1_P2\speed#>0 Then T1_P2\speed#=T1_P2\speed#-.0005
		EndIf
		If T1_P2\speed#<0 Then T1_P2\speed#=0
		If KeyDown(Player_1_DOWN) Then T1_P2\speed#=T1_P2\speed#-.01
	Next
EndIf
End Function

Function Sort_Distance()
	For c.ball=Each ball
	If puck_under_control_player_num=1
	    For T1_P2.Team_1_P2=Each Team_1_P2
		    ;player 2
		    If EntityDistance(c\e,T1_P2\entity)<=EntityDistance(c\e,pass_1)
		    If EntityDistance(c\e,T1_P2\entity)<=EntityDistance(c\e,pass_2)
		    EntityParent Pass_Target,T1_P2\entity
			EndIf
			EndIf
		    ;pass 1
		    If EntityDistance(c\e,pass_1)<=EntityDistance(c\e,pass_2)
		    If EntityDistance(c\e,pass_1)<=EntityDistance(c\e,T1_P2\entity)
		    EntityParent Pass_Target,pass_1
			EndIf
			EndIf
			;pass 2
		    If EntityDistance(c\e,pass_2)<EntityDistance(c\e,pass_1)
		    If EntityDistance(c\e,pass_2)<=EntityDistance(c\e,T1_P2\entity)
		    EntityParent Pass_Target,pass_2
			EndIf
			EndIf
			PositionEntity Pass_Target,0,0,0
		Next
	EndIf
	
	If puck_under_control_player_num=2
	    For T1_P1.Team_1_P1=Each Team_1_P1
		    ;player 2
		    If EntityDistance(c\e,T1_P1\entity)<=EntityDistance(c\e,pass_1)
		    If EntityDistance(c\e,T1_P1\entity)<=EntityDistance(c\e,pass_2)
		    EntityParent Pass_Target,T1_P1\entity
			EndIf
			EndIf
		    ;pass 1
		    If EntityDistance(c\e,pass_1)<=EntityDistance(c\e,pass_2)
		    If EntityDistance(c\e,pass_1)<=EntityDistance(c\e,T1_P1\entity)
		    EntityParent Pass_Target,pass_1
            EndIf
			EndIf
			;pass 2
		    If EntityDistance(c\e,pass_2)<EntityDistance(c\e,pass_1)
		    If EntityDistance(c\e,pass_2)<=EntityDistance(c\e,T1_P1\entity)
		    EntityParent Pass_Target,pass_2
			EndIf
			EndIf
			PositionEntity Pass_Target,0,0,0
		Next
	EndIf
	Next
End Function



Bot Builder(Posted 2004) [#3]
Well, to me it looks like you've got tons of repetition in there. What's the point of having seperate types if 99.9% of the time they do the same thing?

Also, here it seems to work fine. The only problems come in whent he terget is moving.