geting a object to rotate around another when clos

Blitz3D Forums/Blitz3D Beginners Area/geting a object to rotate around another when clos

MaximusPrimal(Posted 2008) [#1]
Hi,

I need to make an object roate around another when it gets close to it. I.e it comes in close, does a 180 spin around the object and slingshots back the way it comes...

I have managed to get two simple shapes get close. One spins on it's pivot while moving.

When they get close enough I try to unparent the pivot and then re-parent the pivot and shape to the pivot of the other object so they can rotate around that. But it doesn't appear to work.

This is what I have:

	Graphics3D 800,600
	SetBuffer BackBuffer()
	camera=CreateCamera()
	CameraViewport camera,0,0,800,600
	
	light=CreateLight()
	
	cp1=CreatePivot()
	cube1=CreateCube(cp1)
	PositionEntity cp1,10,3,15
	
	
	cp2=CreatePivot()
	cube2=CreateSphere(20,cp2)
	PositionEntity cube2,-10,0,15
	EntityColor cube2,0,255,0
	
	Dir=1
	
	While Not KeyHit(1)
	TurnEntity cube1,0,0,1
	
	
	
	If Dir=1
	MoveEntity cp1,-0.1,0,0
	EndIf
	
	If Dir=2
	MoveEntity cp1,0.2,0,0
	EndIf
	
	dist=EntityDistance(cube1,cube2)
	
	If dist<5
	Dir=2
	EntityParent(cube1,0)
	EntityParent(cube1,cp2)
	EntityParent(cp1,cp2)
	For c=0 To 360
	RotateEntity cube1,0,0,-.5
	RotateEntity cp1,0,0,-.5
	UpdateWorld
	RenderWorld
	Flip
	Next
	
	EntityParent(cube1,0)
	EntityParent(cp2,0)
	EntityParent(cub1,cp2)
	
	EndIf 
	
	UpdateWorld
	RenderWorld
	Flip
	Wend
End


Can some one tell me what I am doing wrong, or if I am approaching this from totaly the wrong angle.

Any thoughts are very welcomed on this.

Thanks

Max


Dabhand(Posted 2008) [#2]
Well, I dont have Blitz3D no more, but, if I was doing it and the pivot route was a bit of a mare, I'd send the entity to be slingshotted (In this case, the source entity) and check its distance from the destination entity, once it got so close, I'd use the destination entitys position and its distance in a typical Sin/Cos forumla to sweep the source entity around the destination entity.

You can check how far its gone round, and after its performed a semi-circle sweep, unclip it from the Sin/Cos routine and send it on its merry way! :)