@name Hovercar
@inputs Pod:wirelink [Base Seat]:entity
@outputs 
@persist Height Deltas:array Size:vector2
@trigger 

if(first()){
    runOnTick(1)
    
    Height = 30
    Size = vec2(2,2)
    
    for (N = 0,Size[1]*Size[2]-1) {
        holoCreate(N)
        holoParent(N,Base)
    }
} else {
    local LSize = Size-vec2(1)
    local Count = (Size[1]*Size[2])/6

    for (X = 0,LSize[1]) {
        for (Y = 0,LSize[2]) {
            rangerFilter(Base)
            rangerFilter(Seat)
            local LPos = Base:toWorld((vec(X/LSize[1],Y/LSize[2],0)*2-1)*Base:boxMax()*0.8)
            local Up = Base:up()
            local RD = rangerOffset(LPos+5,LPos-Up*Height)
            if (RD:hit()) {Base:applyOffsetForce((Up*((Height-RD:distance())-(LPos-Deltas[X+Y*Size[1]+1,vector])*3)*Base:mass())/Count,LPos)}
            
            Deltas[X+Y*Size[1]+1,vector] = LPos
            holoPos(X+Y*Size[1],RD:pos())
        }
    }
}

local Seat = Pod["Entity",entity]
local Driver = Seat:driver()
local Active = Driver:isPlayer()
local W = Driver:keyForward()
local A = Driver:keyLeft()
local S = Driver:keyBack()
local D = Driver:keyRight()
local Space = Driver:keyJump()
local Shift = Driver:keySprint()
local M1 = Driver:keyAttack1()
local M2 = Driver:keyAttack2()

Base:applyForce(Base:right() * Base:velL() * Base:mass() + Base:forward() * (W-S) * Base:mass() * 6)
Base:applyAngForce((A - D) * Base:mass() * 5 + Base:angVel() * Base:mass())
