|
| 1 | +@name GG5-HOLO V1.3 |
| 2 | +@inputs [Gun]:entity [Active R PrevWeapon NextWeapon]:number Base:entity [Cam]:wirelink MuzzleVel [HAxis,VAxis,VAxis2]:entity |
| 3 | +@persist [Position]:vector CamDistance FOV |
| 4 | +@outputs [Ops]:number |
| 5 | +@outputs [Self]:entity |
| 6 | +@outputs [Filter]:array |
| 7 | +@persist [Inertia GunAng]:angle |
| 8 | +@persist [MaxElevation MaxDepression MinYaw MaxYaw RotateSpeed Unlock Interval]:number |
| 9 | +@trigger Active PrevWeapon NextWeapon R |
| 10 | + |
| 11 | +#ChunderDownUndeR |
| 12 | + |
| 13 | +#v1.1 Changes-wirelink to streamline setup, Mup,Mdown to prev/next weapon to instant wire to pod |
| 14 | +#v1.2 Added Dual axis option (Wiring Vaxis2 will creat a seperate rotation joint for positive gun elevation) |
| 15 | +#v1.3 No longer retarded |
| 16 | +#Changed code to allow a sideways, or upside down gun which was otherwise unable to make turret work properly |
| 17 | + |
| 18 | +#-----Setup----- |
| 19 | +#R-Toggles turret lock/unlock |
| 20 | +#PrevWeapon/NextWeapon-Zoom increment |
| 21 | + |
| 22 | +#VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV |
| 23 | +#Haxis and Vaxis is the reference entity for center of rotation and oscillation respectively. |
| 24 | + |
| 25 | +#To put it simple this is where your guns rotate on pitch and yaw axis (eg:turret ring can be haxis) |
| 26 | +#having your Haxis destroyed infight will not destroy the turret / parenting. but will if you reset the chip |
| 27 | +#Vaxis2 is an optinal input which will create a second joint of pitch for dual axis. Vaxis becomes point of depression and Vaxis2 becomes point of elevation with gun pitch |
| 28 | + |
| 29 | +#NOTE:Dual axis guns cant have the E2 updated on an unfrozen/used dupe without displacing the gun |
| 30 | +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 31 | + |
| 32 | +#If you are working on a WIP do not unfreeze it to test if the turret works because that gets rid of parenting on some servers |
| 33 | +#Dupe it and paste it if this happens and remember to save regulary babes |
| 34 | + |
| 35 | +#Any other questions or issues please contact ChunderDownUndeR Via Steam/discord/Gmod |
| 36 | + |
| 37 | +#ACF2 > Acf3 |
| 38 | + |
| 39 | + |
| 40 | +if(first()|dupefinished()){ |
| 41 | + Self=entity() |
| 42 | + GunAng = Self:toLocal(Gun:angles()) |
| 43 | + # Orient=Self:toWorld(ang(0,GunAng:yaw(),0)) |
| 44 | + |
| 45 | +holoCreate(3,HAxis:pos(),vec(0.3),Self:toWorld(ang(0,GunAng:yaw(),0))) |
| 46 | +holoAlpha(3,0) |
| 47 | + |
| 48 | +holoCreate(2,VAxis:pos(),vec(0.3),Gun:angles():setRoll(0)) |
| 49 | +holoAlpha(2,0) |
| 50 | + |
| 51 | +VAxis:parentTo(holoEntity(2)) |
| 52 | +HAxis:parentTo(holoEntity(3)) |
| 53 | +holoParent(3,Self) |
| 54 | +holoParent(2,3) |
| 55 | +if(VAxis2){ |
| 56 | +holoCreate(4,VAxis2:pos(),vec(0.3),Gun:angles():setRoll(0)) |
| 57 | +holoAlpha(4,0) |
| 58 | +holoParent(4,2) |
| 59 | +VAxis2:parentTo(holoEntity(4)) |
| 60 | +Gun:parentTo(holoEntity(4)) |
| 61 | +} |
| 62 | +else{Gun:parentTo(holoEntity(2))} |
| 63 | +} |
| 64 | +if ( changed(Active) ) { |
| 65 | + |
| 66 | + Interval = 100 #Higher the number the more the optimized |
| 67 | + |
| 68 | + MaxElevation = 15 #---How High you can aim up (in degrees)---# |
| 69 | + MaxDepression = 15 #---How Low you can aim down (in degrees)---# |
| 70 | + MinYaw = 360 #---Keep This at 360. If making a tank destroyer or bow gun, make it 20 and 20---# |
| 71 | + MaxYaw = 360 #---Keep This at 360. If making a tank destroyer or bow gun, make it 20 and 20---# |
| 72 | + Position = vec(-5, 14, 110) #---Where your camera will be floating---# (left/right,up/down,forward/back) |
| 73 | + CamDistance = 130 #---Camera Radius around the Camera Position---# |
| 74 | + RotateSpeed = 80 #---Turret Rotation Speed in Degrees per Second---# |
| 75 | + # Self = entity() #---Ignore this shit, doesn't need to be touched---# |
| 76 | +# -DO NOT TOUCH ANYTHING ELSE UNDER THIS. |
| 77 | +#--------------------------------------------------------------------------------------------------------------# |
| 78 | + # Automatic settings |
| 79 | + Filter = Filter = Gun:getConnectedEntities() # Ranger filter |
| 80 | + Filter:pushEntity(Gun) |
| 81 | + |
| 82 | + RotateSpeed/=20 |
| 83 | + # GunAng = Self:toLocal(Gun:angles()) |
| 84 | + Inertia = shiftL(ang(Gun:inertia())):setRoll(0) |
| 85 | + Unlock = 0 |
| 86 | + FOV = 90 |
| 87 | + Cam["Filter",array]=Filter |
| 88 | + Cam["Position",vector]=Base:toWorld(Position) |
| 89 | + Cam["Parent",entity]=Base |
| 90 | + Cam["Activated",normal]=Active |
| 91 | + #Ra = Cam["Trace",ranger] |
| 92 | + Cam["Distance",normal] = CamDistance |
| 93 | + |
| 94 | +} |
| 95 | +elseif ( inputClk() ) { |
| 96 | + if( PrevWeapon ) { FOV = max(FOV/2, 5) } |
| 97 | + elseif ( NextWeapon ) { FOV = min(FOV*2, 90)} |
| 98 | + elseif( changed(R) & R ) { |
| 99 | + if ( Unlock ) { Unlock = 0 } |
| 100 | + else { Unlock = 1 , interval(Interval) } |
| 101 | + |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +if(changed(FOV)){Cam["FOV",normal]=FOV} |
| 106 | + |
| 107 | +if ( Unlock & clk() ) { |
| 108 | + |
| 109 | + T = ((Cam["Trace",ranger]:distance()*1.27) / 39.3701) / (MuzzleVel ) #0.032258 * Ra:distance() instead of (Ra:distance()*1.27) / 39.3701) |
| 110 | + |
| 111 | + Drift = (Base:vel() * T) |
| 112 | + Drop = (0.5 * 9.8 * T^2) * 39.3701 |
| 113 | + |
| 114 | + GunDir=(((Cam["Trace",ranger]:pos()- vec(0,0,-Drop)) - Drift) -Gun:massCenter()):normalized() |
| 115 | + # GunDir = Gun:heading(AimPos) |
| 116 | + GunAng = angnorm(clamp(GunAng - clamp(heading(vec(), GunAng, Self:toLocalAxis(GunDir)), -RotateSpeed, RotateSpeed), ang(-MaxElevation,-MinYaw, 0), ang(MaxDepression, MaxYaw, 0))) |
| 117 | + |
| 118 | + GunYaw = Self:toWorld(ang(0,clamp(GunAng:yaw(),-MinYaw,MaxYaw),0)) |
| 119 | + holoAng(3,GunYaw) |
| 120 | + GunPitch = ang(clamp(GunAng:pitch(),-MaxElevation,MaxDepression),0,0) |
| 121 | + if(VAxis2){ |
| 122 | + holoAng(2,holoEntity(3):toWorld(GunPitch:setPitch(max(GunPitch:pitch(),0)))) |
| 123 | + holoAng(4,holoEntity(2):toWorld(GunPitch:setPitch(min(GunPitch:pitch(),0)))) |
| 124 | + |
| 125 | + }else{ |
| 126 | + holoAng(2,holoEntity(3):toWorld(GunPitch))} |
| 127 | + |
| 128 | + interval(Interval) |
| 129 | + Ops=ops() |
| 130 | +} |
| 131 | + |
0 commit comments