tracking distance of entity movement

Blitz3D Forums/Blitz3D Beginners Area/tracking distance of entity movement

timmport(Posted 2006) [#1]
I have set up a key press to move an entity around my blitz project. I want to track (print to screen) the total distance the entity has traveled while the project is open. However I am having a bit of trouble with this. I have only been able to print the increment by which the entity is being moved. Can someone point out what I should be doing?

Graphics3D 640,480,16,2 
SetBuffer BackBuffer() 

camera=CreateCamera() 
light=CreateLight() 

cone=CreateCone( 32 ) 
PositionEntity cone,0,0,5 

While Not KeyDown( 1 ) 

; Reset turn values - otherwise, the cone will not stop turning! 
x#=0 
y#=0 
z#=0 

; Change movement values depending on the key pressed 
If KeyDown( 208 )=True Then x#=-1 
If KeyDown( 200 )=True Then X#=1 
If KeyDown( 203 )=True Then y#=-1 
If KeyDown( 205 )=True Then y#=1 
If KeyDown( 45 )=True Then z#=-1 
If KeyDown( 44 )=True Then z#=1 

; Move sphere using movement values 
moveEntity cone,x#,y#,z# 

RenderWorld 

Text 0,0,"Use cursor/Z/X keys to turn cone" 
Text 0,20,"x: "+x# 
Text 0,40,"y: "+y# 
Text 0,60,"z: "+z# 

Flip 

Wend 

End 


UPDATE:
I modified the code so that it moved rather than rotated


Brumie(Posted 2006) [#2]
I'don't have a lot of experiance, but it looks like the cone itself isn't acually moving like it would be if you were moving it accross a floor or thru' the air. I mean I know its moving but the point about which it rotates is not moving. It stays in the same spot. Maybe that has something to do with it.


Matty(Posted 2006) [#3]
[code]
;in your main loop include the following lines

oldxpos#=currentxpos#
oldypos#=currentypos#
oldzpos#=currentzpos#

currentxpos#=entityx(cone)
currentypos#=entityy(cone)
currentzpos#=entityz(cone)

distancetravelledbetweenframe#=sqr((oldxpos-currentxpos)^2+(oldypos-currentypos)^2+(oldzpos-currentzpos)^2)
distancetravelledsofar#=distancetravelledsofar#+distancetravelledbetweenframe#

[code]

Although looking at your code you are not moving the cone you are simply turning it on the spot.


Stevie G(Posted 2006) [#4]
Yip, the distance travelled in this case is 0.