@name Tenticle Legs
@inputs [Base Foot]:entity
@persist N Count Vl
interval(125)
if(first())
{
    runOnLast(1)
    
    function ikS(Dist,I1,I2,Src:vector,End:vector)
    {
        local D = Src-End
        local L = min(D:length(),Dist)
        local A1 = D:toAngle()
        local A2 = ang(-asin(L/Dist),0,0)
        holoAng(I1,A1+A2)
        holoAng(I2,A1-A2)
    }
    function ikSI(Dist,I1,I2,Src:vector,End:vector)
    {
        local D = Src-End
        local L = min(D:length(),Dist)
        local A1 = D:toAngle()+ang(180,0,0)
        local A2 = ang(asin(L/Dist),0,0)
        holoAng(I1,A1+A2)
        holoAng(I2,A1-A2)
    }
    function vector bezier2(Src:vector,End:vector,CurvePoint1:vector,CurvePoint2:vector,Progress:number)
    {
        local M1 = mix(mix(End,CurvePoint2,Progress),mix(CurvePoint2,CurvePoint1,Progress),Progress)
        local M2 = mix(mix(CurvePoint2,CurvePoint1,Progress),mix(CurvePoint1,Src,Progress),Progress)
        return mix(M1,M2,Progress)
    }
    
    Count = 10
    
    holoCreate(1,Base:toWorld(vec()),vec(1),Base:toWorld(ang()))
    holoCreate(2,Base:toWorld(vec(0,0,75)))
    holoCreate(3,Base:toWorld(vec()),vec(1),Base:toWorld(ang()))
    
    holoParent(1,Base)
    holoParent(2,1)
    holoParent(3,2)
    
    holoCreate(4,Base:toWorld(vec()),vec(1),Base:toWorld(ang()))
    holoCreate(5,Base:toWorld(vec(0,0,50)))
    holoCreate(6,Base:toWorld(vec()),vec(1),Base:toWorld(ang()))
    
    holoParent(4,Base)
    holoParent(5,4)
    holoParent(6,5)
    
    holoAlpha(1,0)
    holoAlpha(2,0)
    holoAlpha(3,0)
    holoAlpha(4,0)
    holoAlpha(5,0)
    holoAlpha(6,0)
}

if(N < Count)
{
    while(holoCanCreate() & perf() & N < Count)
    {
        N++
        
        local J = N+6
        holoCreate(J)
        holoModel(J,"models/noesis/donut.mdl")
        holoMaterial(J,"models/antlion/antlion_innards")
        holoScale(J,vec(2,0.25+(Count-N)/Count,0.25+(Count-N)/Count))
    }
}

for(I=1,Count)
{
    local J = I+6
    holoPos(J,bezier2(Base:pos(),Foot:pos(),holoEntity(2):pos(),holoEntity(5):pos(),(I)/Count))
    holoAng(J,I == 1 ? (Base:pos()-holoEntity(J):pos()):toAngle() : (holoEntity(J-1):pos()-holoEntity(J):pos()):toAngle())
}

ikS(125,1,2,Base:pos(),Foot:pos())
ikSI(100,4,5,Base:pos(),Foot:pos()+vec(0,0,25))
