Skip to content

Instantly share code, notes, and snippets.

@CheezusChrust
Created September 17, 2023 22:37
Show Gist options
  • Save CheezusChrust/76fe99d80533d2543437cc976d0a49ac to your computer and use it in GitHub Desktop.
Save CheezusChrust/76fe99d80533d2543437cc976d0a49ac to your computer and use it in GitHub Desktop.
Actuating nozzle for a jet engine, give it an A value of 0 to 1
@name Jet Nozzle
@inputs A
@outputs Value
@persist MoveRate Value Segments Distance MinAng MaxAng [MainScale Scale1 Scale2]:vector
@persist StartAngles:array LastValue First
@trigger none
@strict
if(first() | dupefinished()) {
MoveRate = 0.1 # Rate at which nozzle can move
Segments = 16 # Number of nozzle segments
Distance = 12 # Distance from the center of the E2
MinAng = 2 # Nozzle angle at A=0
MaxAng = 14 # Nozzle angle at A=1
MainScale = vec(1.75)
Scale1 = vec(0.4, 0.3, 4) # Main segments
Scale2 = vec(0.4, 0.1, 4) # Inner segments
Value = 0
LastValue = 0
StartAngles = array()
Segments = Segments * 2
First = 1
local Div = 360 / Segments
for(I = 1, Segments) {
local CurAng = I * Div
local WPos = entity():toWorld(vec(sin(CurAng) * Distance, cos(CurAng) * Distance, 0) * MainScale)
local WAng = entity():toWorld(ang(0, -CurAng, 0))
holoCreate(I, WPos, vec(0.1), WAng, vec4(0, 0, 0, 0))
holoParent(I, entity())
StartAngles[I, angle] = ang(0, -CurAng, 0)
}
timer("holos2", 1000)
}
if(clk("holos2")) {
timer("tick", 100)
local N = Segments + 1
for(I = N, N + Segments - 1) {
local RootHolo = holoEntity(I - Segments)
local WPos = RootHolo:toWorld(vec(0, 0, 10) * MainScale)
local WAng = RootHolo:toWorld(ang())
holoCreate(I, WPos, Scale1, WAng)
holoParent(I, RootHolo)
if(I % 2 == 1) {
holoColor(I, vec(200))
holoScale(I, Scale2 / 5 * MainScale)
holoModel(I, "models/sprops/triangles_thin/regular/t_etri_30x30.mdl")
holoAng(I, holoEntity(I):toWorld(ang(0, 0, 180)))
holoMaterial(I, "WTP/track_2b")
} else {
holoScale(I, Scale1 * MainScale)
holoModel(I, "models/sprops/geometry/t_hhex_12.mdl")
holoMaterial(I, "WTP/track_3b")
}
}
}
if(clk("tick")) {
timer("tick", 100)
Value = Value + clamp(A - Value, -MoveRate, MoveRate)
if(Value != LastValue | First) {
local Ang = remap(Value, 0, 1, MinAng, MaxAng)
for(I = 1, Segments) {
local StartAngle = StartAngles[I, angle]
holoAng(I, entity():toWorld(StartAngle + ang(0, 0, Ang)))
}
First = 0
}
LastValue = Value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment