@name ApplyForce 
@persist E:entity Prop:entity EndProp:entity Force:angle Posi:vector Props:array Timer POS:vector Pso Dist
@trigger all


if(first() | duped()){
runOnTick(1)
runOnLast(1)  

E = entity()
Prop = propSpawn("models/hunter/blocks/cube2x4x05.mdl",E:toWorld(vec(0,0,10)),ang(0,0,0),0)
Prop:setMass(500)

EndProp = propSpawn("models/hunter/blocks/cube025x025x025.mdl",E:toWorld(vec(0,0,200)),ang(0,0,0),1)
EndProp:setPos(E:toWorld(vec(0,0,200)))
Dist = E:pos():distance(EndProp:pos())


Pso = 0
}




#

local V_APPLY = Prop:toLocal(rotationVector(quat(ang(0,0,0))/quat(Prop))+Prop:pos())
#POS = E:toWorld(vec(0,0,5 + abs(cos(Timer*2) * 100) )) - Prop:pos()
#Prop:applyForce((POS*200 + $POS*500))
Prop:applyTorque((100*V_APPLY - 50*Prop:angVelVector())*Prop:inertia())

local Speed = 0.5

local Mix = mix(E:toWorld(vec(0,0,10)),EndProp:pos(),Timer / Dist)
local Dir = (Mix-Prop:massCenter()) * 50


if(Timer / Dist >= 1){
 Timer = 0   
 Dist = E:pos():distance(EndProp:pos())
}else{
 Timer += 2
}

Prop:applyForce((Dir-Prop:vel())*Prop:mass())
#Prop:setPos(POS)


if(last()){
 EndProp:propDelete()
 Prop:propDelete()
}
