Is There a Way to Optimize My Interpolation Function?

I made this function a bit ago to find the exact center between two holos, then set the angle of the holo and the scale. I noticed it was running on around 1.4k ops, I’m not very good with E2 and sometimes get messy with my code so I was wondering if there was a way to optimize it a bit. Thanks :slight_smile:

function void holoAttach(Index,Index2,Index3){

local CalcX = (holoEntity(Index2):pos():x()+holoEntity(Index3):pos():x())/2
local CalcY = (holoEntity(Index2):pos():y()+holoEntity(Index3):pos():y())/2
local CalcZ = (holoEntity(Index2):pos():z()+holoEntity(Index3):pos():z())/2
    
holoPos(Index,vec(CalcX,CalcY,CalcZ))
holoAng(Index,(holoEntity(Index2):pos()-holoEntity(Index3):pos()):toAngle())
holoScaleUnits(Index,vec(holoEntity(Index2):pos():distance(holoEntity(Index3):pos())-5,2.5,2.5))

}



function holoAttack(Middle:number, First:number, Second:number)
{
    local Pos1 = holoEntity(First):pos()
    local Pos2 = holoEntity(Second):pos()

    holoPos(Middle, (Pos1 + Pos2) / 2)
    holoAng(Middle, (Pos1 - Pos2):toAngle())
    holoScaleUnits(Middle, vec(Pos1:distance(Pos2) - 5, 2.5, 2.5))
}


Many functions in E2 have a high op count so localizing results is better for things like holoEntity. Also are you creating this function in an if(first()) statement? If not then that’s one of your problems as it’s recreating the function every update.

I would say post this on the Wiremod forums but they’re down right now, but when they come back up do post on there as you’ll get a better response.

Yeah I have it on the if(first()), and yeah I was gonna post it on Wiremod forums but as you said they are down, thanks for the reply though :slight_smile: