Guest_imported
New member
- Jan 1, 1970
- 0
Hi!
Can anyone help me with the following script?
The goal is for a sphere to move along a circular path with the coordinates from a .txt file. The coords are processed
in this script, then i send the x,y,z to a animation program called EON. This script, On_Float_in(), is executed once every second and with the subs On_increaseSpeed() and On_decreaseSpeed() i change the speed of the sphere.
The script as it is now, works one round of the path...but the 2nd round it looses track of the path and
starts to go off trail. What i need is something to check so that the sphere stays on the path, no matter how fast
it moves.
Is there any of you scripting masters willing to take on this challange
Id appreciate is verry much, since ive been stuck with this for over a week now.
oh btw, there might me some confusing code that doesnt do anything, but i havent cleaned up the code just yet.
Thanks in advance!
/Thomas
Can anyone help me with the following script?
The goal is for a sphere to move along a circular path with the coordinates from a .txt file. The coords are processed
in this script, then i send the x,y,z to a animation program called EON. This script, On_Float_in(), is executed once every second and with the subs On_increaseSpeed() and On_decreaseSpeed() i change the speed of the sphere.
The script as it is now, works one round of the path...but the 2nd round it looses track of the path and
starts to go off trail. What i need is something to check so that the sphere stays on the path, no matter how fast
it moves.
Is there any of you scripting masters willing to take on this challange
Id appreciate is verry much, since ive been stuck with this for over a week now.
oh btw, there might me some confusing code that doesnt do anything, but i havent cleaned up the code just yet.
Thanks in advance!
/Thomas
Code:
------------- CODE ----------------------------------
dim posArr(), lastPoint
sub Initialize()
dim tmpArr, sPos(2)
MPS=0
lastPoint=-0
set a=createObject("scripting.fileSystemobject")
set f1=a.OpenTextFile(".\coords.txt")
b=f1.readAll
tmpArr = split(b, vbCrLf)
redim posArr(CInt(tmpArr(0))-1, 2)
'msgbox(Ubound(posArr, 1) & " : " & Ubound(posArr, 2))
falt=0
for i=1 to Ubound(tmpArr)-1 step 2
tmpArr(i)=trim(tmpArr(i))
coords=split(tmpArr(i), " ")
posArr(falt,0)=coords(0)/100000
posArr(falt,2)=coords(1)/100000
posArr(falt,1)=coords(2)/100000
falt=falt+1
next
Str=""
for i = 0 to uBound(posArr)
Str=Str & posArr(i,0) & " : " & posArr(i,1) & " : " & posArr(i,2) & vbCrLF
next
'msgbox(Str)
sPos(0)=posArr(0,0)
sPos(1)=posArr(0,1)
sPos(2)=posArr(0,2)
StartPos=sPos
ActivateTimer=true
end sub
sub On_Float_in()
dim vector1, vector2
dim position(2), posFixer(2)
bollPos=ballPos 'Ballpos is the spheres location returned from EON.
apa=lastPoint
nextPoint=apa+1
if nextPoint=Ubound(posArr)+1 then nextPoint=0
lengthX=posArr(nextPoint, 0) - posArr(lastPoint, 0)
lengthY=posArr(nextPoint, 1) - posArr(lastPoint, 1)
lengthZ=posArr(nextPoint, 2) - posArr(lastPoint, 2)
currLengthX=bollPos(0)-posArr(lastPoint, 0)
currLengthY=bollPos(1)-posArr(lastPoint, 1)
currLengthZ=bollPos(2)-posArr(lastPoint, 2)
vector1=sqr(lengthX^2 + lengthY^2 + lengthZ^2)
vector2=sqr(currlengthX^2 + currlengthY^2 + currlengthZ^2)
position(0)=LengthX/vector1*MPS
position(1)=LengthY/vector1*MPS
position(2)=LengthZ/vector1*MPS
posOut=position 'sending out position coords.
if vector2>vector1 then
lastPoint=lastPoint + 1
if lastPoint=uBound(posArr)+1 then lastPoint=0
posFixer(0)=posArr(lastpoint, 0)
posFixer(1)=posArr(lastpoint, 1)
posFixer(2)=posArr(lastpoint, 2)
'fixPos=posFixer
end if
end sub
sub On_increaseSpeed()
MPS=round(MPS+1.0, 1)
end sub
sub On_decreaseSpeed()
MPS=round(MPS-1.0, 1)
end sub
------------- CODE ENDS ----------