Target system

Blitz3D Forums/Blitz3D Programming/Target system

In the fps game I am working on; it uses Tokamak. (Are you still with me?) I want to make the player lock on to a target when the control button is is hit. I have that part doen using a blitz linepick. It then gives the world location, distance and the entity, and using this info creates a pivot, that is a child to the selected target. I have all this part done.
Now the hard part I can't figure out to do is, I would like the player to rotate around that pivot, so that the player model and the camera (child of the player model) points to that pivot and stayes locked in distance, so that is the radius of travel. It must point ant the target but move using tokarb_impulse, while still changing its pitch yaw to the terrain. Anyone have some Ideas on how to do this?

My second question is about the return value you get for the PickedEntity ( ) function. It returns a number rather than the name I have assigned. I asume this is the memory address? Anyhow how do I go about using that to change it back into my yariable name.

Here is the relivent code.


;player objects created at the start of program
obj = CreateCube()
ScaleEntity obj,1.0,0.1,1.0
EntityType obj,Type_obj
EntityBox obj,-1,-1,-1,2,.2,2
EntityRadius obj,1,.2
 
rb = TOKRB_Create()
TOKRB_AddBox rb,2.0,0.2,2.0
TOKRB_SetPosition rb,0.0,1.0,0
TOKRB_SetLinearDamping rb,0.007
TOKRB_SetAngularDamping rb,0.085
TOKRB_SetMass rb,2.0
TOKRB_SetBoxInertiaTensor rb,2.0,0.2,2.0,2.0  
EntityColor obj,Rnd(100,230),Rnd(100,230),Rnd(100,230) 
camera = CreateCamera()
num_sensors=4

;Type setup
;LinePick ( x#,y#,z#,dx#,dy#,dz#[,radius#] )
Type target
	Field x#,y#,z#
	;Field dx#,dy#,dz#
	Field distance#
	Field rot_center
	Field parent_ent
End Type
Function lock_on_target(x#,y#,z#,distance#,target)
	center.target=New target
	center\x#=x#
	center\y#=y#
	center\z#=z#
	center\distance#=distance#
	
	center\parent_ent=ent
	center\rot_center=CreatePivot(center\parent_ent)
	target_locked = True 
	Return target 
End Function 
Local target_locked = False 
;this is the call to the function and the creation of the pivot

If KeyHit(29) Then 
	targetpick=LinePick (EntityX#(camera,True),EntityY#(camera,True),EntityZ#(camera,True),EntityX#(sphere,True),EntityY#(sphere,True),EntityZ#(sphere,True),5)
	If targetpick<>0 Then 
		px#=PickedX#()
		py#=PickedY#()
		pz#=PickedZ#()
		t=PickedEntity()
		dis#=EntityDistance(camera,t)
		;lock_on_target(EntityX#(camera),EntityY#(camera),EntityZ#(camera),dx#,dy#,dz#,ent)
 		target=lock_on_target(px#,py#,pz#,dis#,target)
		target_locked = True 

		
	EndIf 
	
EndIf 
;This is where the actual rotation would be handeled
;for rotating to the right
ElseIf KeyDown(205)=True And KeyDown(56)=True Then ;alt key
	If target_locked=False Then 
		TFormVector 5,0,0,obj,0
		TOKRB_ApplyImpulse (rb,TFormedX#(),TFormedY#(),TFormedZ#())
		;TFormVector 0,-150,.25,obj,0
		;TOKRB_ApplyTwist (rb,TFormedX#(),TFormedY#(),TFormedZ#())
	ElseIf target_locked = True Then 
		TFormVector 5,0,0,obj,0
		TOKRB_ApplyImpulse (rb,TFormedX#(),TFormedY#(),TFormedZ#())	
		TFormVector 0,-100,.25,obj,0
		TOKRB_ApplyTwist (rb,TFormedX#(),TFormedY#(),TFormedZ#())	
	EndIf 
;This is where the actual rotation would be handeled
;for rotating to the left
ElseIf KeyDown(203)=True And KeyDown(56)=True Then ;alt key
	If target_locked=False Then 
		TFormVector -5,0,0,obj,0
		TOKRB_ApplyImpulse (rb,TFormedX#(),TFormedY#(),TFormedZ#())	
		;TFormVector 0,150,-.25,obj,0
		;TOKRB_ApplyTwist (rb,TFormedX#(),TFormedY#(),TFormedZ#())
	ElseIf target_locked = True Then
	
		TFormVector -5,0,0,obj,0
		TOKRB_ApplyImpulse (rb,TFormedX#(),TFormedY#(),TFormedZ#())	
		TFormVector 0,100,-.25,obj,0
		TOKRB_ApplyTwist (rb,TFormedX#(),TFormedY#(),TFormedZ#())

	EndIf 




pickedentity returns a handle. It's a number, of course. Like all entities. Not a memory adress. Eg:

Enemy=loadmesh("thingie.3ds")
...
p=PickedEntity(..

If p=enemy then print "outch!"