Newton Problem

Blitz3D Forums/Blitz3D Beginners Area/Newton Problem

Wolf1870(Posted 2016) [#1]
Hey! Have a small problem with newton. The sample code is from the explosion. The origin of the explosion has the coordinates 0,0,0. How must I change the code so that the explosion can have different coordinates?

	If (KeyHit(57));create explosion at (0,0,0)
		For p.phx = Each phx
     		;current position
			xx# = phBodyGetX(p\body)
			yy# = phBodyGetY(p\body)
			zz# = phBodyGetZ(p\body)
			dist2# = xx*xx+yy*yy+zz*zz
			;force
			power# = 1000.0
			fx# = power*xx/dist2
			fy# = power*yy/dist2
			fz# = power*zz/dist2
			phBodyAddForce(p\body,fx,fy,fz)
			;and torque
			power2# = 10000.0
			Torque# = power2/dist2
			phBodyAddTorque(p\body,Rnd(-Torque,Torque),Rnd(-Torque,Torque),Rnd(-Torque,Torque))
		Next
	EndIf



Zethrax(Posted 2016) [#2]
Haven't tested this (and don't have time right now) but try subtracting the position you want the explosion to be at from the position of each body.

EDIT: Tested it and it seems to work correctly.

eg.

; For an explosion position at 10, 10, 10
xx# = phBodyGetX(p\body) - 10
yy# = phBodyGetY(p\body) - 10
zz# = phBodyGetZ(p\body) - 10


Wolf1870(Posted 2016) [#3]
Thanks for your help, works exactly as I had imagined. GREAT!!!