Propeller Thrust Expression 2 Code!

While helping another user with his issues with the propeller tool, I mentioned that to my knowledge it was better to use an expression2 chip to apply force in the same direction that the propeller tool would. I didn’t know how the propeller tool calculated the force for a given rotation speed, but I got curious. After about 2 hours of snooping around LUA files and playing the trial and error game, I was able to come up with an expression2 code that works very much like the propeller tool. The code and details are below:



@name Propeller AppForce
@persist Yawvel Thrust:vector PowerLog Boundrad X Y Z Efficiency RPM
@model models/propellers/propeller3x.mdl

runOnTick(1)
if(first()){
X=entity():boxSize():x()/2
Y=entity():boxSize():y()/2
Z=entity():boxSize():z()/2

Efficiency=10 #Same effect as in the propeller tool

Boundrad=sqrt(X^2+Y^2+Z^2) #Attempting to calculate bounding radius
}


Yawvel=abs(entity():angVel():yaw()/2500)

RPM=floor(abs(entity():angVel():yaw()/6))

if(entity():angVel():yaw()>0){PowerLog=ln(1.00001+Yawvel)}
else{PowerLog=-ln(1.00001+Yawvel)}

Thrust=entity():up()*PowerLog*Efficiency*Boundrad*10
entity():applyForce(Thrust)


This E2 is a good deal more powerful than the propeller tool for a given Efficiency, so don’t set it super high.
This E2 IS the propeller. It isn’t a chip you put somewhere else on your contraption, it is the physical propeller itself. Change the model path in the @model header to change the model of the propeller. (As it is above, it is set as Gigabyte’s 3 bladed propeller from his model pack.)
The propeller works equally well and with equal force in both directions. As it is now, the E2 applies forward force for counterclockwise rotation, and backwards force for clockwise rotation.
This expression WILL WORK AT ANY SPEED. It does not suffer from the RPM cutoff that the propeller tool does.

Most of the credit here should go to Out$ider, the creator of the original Propeller tool. About 90% of this code is his that I just dissected, updated, and translated to work for Expression2.