@name Magic Carpet
@inputs Active Ent:entity X W A S D Mouse1
@outputs Fire On
@persist E:entity Ang:angle Pos:vector Speed
@trigger 

O=owner()


runOnTick(1)
if(first()){
    Speed=10
    E = entity():isConstrainedTo(1)
    E:setColor(0,0,255)
}

Pos = O:pos() -vec(0,0,2)
if(O:pos():distance(E:pos())<15){On=1}else{On=0}
if(On){
    rangerFilter(E)
    rangerFilter(entity())
    
    Ang = Ang + ang(0,-X/100,0)
    
    E:applyForce(((Pos-E:massCenter())*Speed-E:vel())*E:mass())
    E:applyAngForce((((Ang )-E:angles())*Speed-E:angVel())*E:mass())
    
    if(Mouse1){
        Fire = 1
    }
    else {
        Fire = 0
    }
}
