@軌跡上に配置ver4（ターゲット）
--track0:後ろ枚数,0,100,0,1
--track1:手前枚数,0,100,0,1
--track2:間隔ms,0,10000,100,1
--dialog:Layer,layP="@-1";x方向/chk,checkX=1;y方向/chk,checkY=1;z方向/chk,checkZ=1;(進行向)平面,HEI="xy";(進行向)回転軸,JIK="z";真ん中を非表示/chk,checkM=0;透明度変化%,da=0;拡大率変化%,dzoom=0;ランダムずらし,CR="/x/y/z";ランダムずらし幅,Rmax=30;


--valueの上限と下限をカットする関数
function cut(value,Max,Min)

	local v

	if(value>Max)then
		v=Max
	elseif(value<Min)then
		v=Min
	else
		v=value
	end

	return v
end
--AをBのばいすうにする　
function bai(a,b)

	local c

	c= math.floor(a/b)*b

	return c
end

dt=obj.track2/1000
dd=obj.track2
T=0
offtime=obj.track2

layp=string.gsub(layP,"@","")
layn=layp

if(string.match(layP,"@"))then
	layn = obj.layer+layp
end

N1=obj.track0
N2=obj.track1

AL=0
ZM=1
ORZ=obj.rz
ORY=obj.ry
ORX=obj.rx
OZM=obj.zoom
OAL=obj.alpha
dt2=1/obj.framerate

obj.effect() 

for i=-N2,N1 do

	t2=bai(obj.time,dt)+i*offtime/1000
	AL=OAL+da*i/100
	ZM=OZM+dzoom*i/100
	AL=cut(AL,1,0)
 	RZ=0
	RY=0
	RX=0

if(t2>=0 and t2<=obj.totaltime)then

	if(checkX==1)then
		X=obj.getvalue("layer"..layn ..".x",t2)
	else
		X=0
	end

	if(checkY==1)then
		Y=obj.getvalue("layer"..layn ..".y",t2)
	else
		Y=0
	end

	if(checkZ==1)then
		Z=obj.getvalue("layer"..layn ..".z",t2)
	else
		Z=0
	end

	seed=t2*1000

	if(string.match(CR,"/x"))then
		X = X+rand(0,Rmax,seed,0)
	end
	if(string.match(CR,"/y"))then
		Y = Y+rand(0,Rmax,seed,1)
	end
	if(string.match(CR,"/z"))then
		Z = Z+rand(0,Rmax,seed,2)
	end
	if(string.match(CR,"/rx"))then
		RX = RX+rand(0,Rmax,seed,3)
	end
	if(string.match(CR,"/ry"))then
		RY = RY+rand(0,Rmax,seed,4)
	end
	if(string.match(CR,"/rz"))then
		RZ = RZ+rand(0,Rmax,seed,5)
	end



		if(t2-dt2>=0)then
			dx=obj.getvalue("layer"..layn ..".x",t2)-obj.getvalue("layer"..layn ..".x",t2-dt2)
			dy=obj.getvalue("layer"..layn ..".y",t2)-obj.getvalue("layer"..layn ..".y",t2-dt2)	
			dz=obj.getvalue("layer"..layn ..".z",t2)-obj.getvalue("layer"..layn ..".z",t2-dt2)	
		else--ごまかし
			dx=obj.getvalue("layer"..layn ..".x",t2+dt2)-obj.getvalue("layer"..layn ..".x",t2)
			dy=obj.getvalue("layer"..layn ..".y",t2+dt2)-obj.getvalue("layer"..layn ..".y",t2)
			dz=obj.getvalue("layer"..layn ..".z",t2+dt2)-obj.getvalue("layer"..layn ..".z",t2)	
		end

		if(HEI=="xy")then
			VR=math.deg(math.atan2(dy,dx))+90
		elseif(HEI=="yx")then
			VR=-(math.deg(math.atan2(dy,dx))+90)	
		elseif(HEI=="yz")then
			VR=math.deg(math.atan2(dz,dy))+90
		elseif(HEI=="zy")then
			VR=-(math.deg(math.atan2(dz,dy))+90)
		elseif(HEI=="zx")then
			VR=(math.deg(math.atan2(dx,dz))+90)
		elseif(HEI=="xz")then
			VR=-(math.deg(math.atan2(dx,dz))+90)
		else
			VR=0
		end


		if(JIK=="z")then
			RZ=RZ+VR
		elseif(JIK=="y")then
			RY=RY+VR
		elseif(JIk=="x")then
			RX=RX+VR
		end


	obj.rx=ORX+RX
	obj.ry=ORY+RY
	obj.rz=ORZ+RZ

	if(checkM==0)then
		obj.draw(X,Y,Z,ZM,AL)
	else
		if(i~=0)then
			obj.draw(X,Y,Z,ZM,AL)
		end
	end
end
end

