Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name HK-drone chip
- @inputs RPod:entity LPod:entity APod:entity Pod:wirelink
- @outputs RThrust LThrust AThrust
- #These persists are for the 3 thruster pod's pitches
- @persist RPitch LPitch APitch
- #these persists are for calculation the height
- @persist ZOffset Altitude
- #these persists are the angles and motion of the body of the craft
- @persist Roll Pitch AngVel ForwardVel SideVel
- #these persists are needed for countering some motions
- @persist SpeedCounter SpinCounter
- #Torque
- @persist Torque
- interval(50)
- if(first() | duped()){
- Altitude=entity():pos():z()
- #Torque is the strength of the pod rotation
- Torque=70
- Altitude=entity():pos():z()
- gSetGroup("E_Debugger")
- gShare(1)
- }
- if(gGetNum("HKDroneDrivable")==1){
- selfDestruct()
- }
- ###Adv. Pod contrller Wirelinks ----------------------------------------------------
- #(depreciated look on the expression 2 wiki for updates)
- Active=Pod:number("Active")
- W=Pod:number("W")
- A=Pod:number("A")
- S=Pod:number("S")
- D=Pod:number("D")
- Mouse1=Pod:number("Mouse1")
- Mouse2=Pod:number("Mouse2")
- Space=Pod:number("R")
- Shift=Pod:number("Space")
- Alt=Pod:number("Alt")
- Driver=Pod:entity("Entity"):driver()
- AimPos=Pod:vector("AimPos")
- Bearing=Pod:number("Bearing")
- Elevation=Pod:number("Elevation")
- ###Minimum Height----------------------------------------------------
- #Use E2 ranger to find the ground so it won't "try" to go below it
- #The ranger filter is so it won't detect the body since the ranger/E2 is on top
- rangerHitWater(1)
- rangerFilter(entity():isWeldedTo())
- RD=rangerOffset(9999999,entity():pos(),vec(0,0,-1))
- Ground=RD:position():z()+40
- ###Flying Altitude----------------------------------------------------
- #This if statement will reset the calculated altitude so it won't fly up when you turn it on
- if(!Active){
- #Altitude=entity():pos():z()
- }
- #Anything following this will not happen unless you activate the pod controller
- #if(Active){
- #These if statements increase or decrease the craft's height
- #Change the 3 to something higher to increase climb/decend rate
- if(Shift){
- Altitude=Altitude+6
- }elseif(Space){
- #print("alt decrease")
- Altitude=Altitude-6
- }
- ###Maintain Altitude----------------------------------------------------
- #this section will calculate how much thrust is needed to get up to the target altitude
- RealZ=entity():pos():z()
- ZOffset=(Altitude-RealZ)
- HoverThrust=(ZOffset+$ZOffset*10)*1
- ###Hover Balance----------------------------------------------------
- #These lines are what keep the craft upright (no keep upright stool)
- #They only affect the strength of the thrusters
- Angles=entity():angles()
- Roll=Angles:roll()
- Pitch=Angles:pitch()
- RollCounter=(Roll+$Roll*3)*3
- PitchCounter=(Pitch+$Pitch*2)*5
- ###Counter Movement----------------------------------------------------
- #The next 3 lines find the velocities (and/or accelerations with $)
- ForwardVel=entity():velL():x()
- SideVel=entity():velL():y()
- AngVel=entity():angVel():yaw()
- #The if statements keep it from countering it's own desired movement
- if(W|S){
- SpeedCounter=0
- }else{
- SpeedCounter=(ForwardVel+$ForwardVel*0)/12
- }
- if(A|D){
- SpinCounter=0
- }else{
- SpinCounter=(AngVel+$AngVel*0)/3
- }
- #And StrafeCounter stops side to side sliding motion
- #StrafeCounter and RollCounter affect each other because it increases its roll
- #in order to stop strafing
- StrafeCounter=(SideVel+$SideVel*1)/1.5
- ###Thruster thrust----------------------------------------------------
- #These lines put all of the required calculations that can be changed by the pods' thrust
- #strength (like hover height
- RThrust=clamp((HoverThrust/cos(Pitch))+RollCounter-StrafeCounter,0,50)
- LThrust=clamp((HoverThrust/cos(Pitch))-RollCounter+StrafeCounter,0,50)
- AThrust=clamp(HoverThrust/cos(Pitch)-PitchCounter,0,50)
- ###Angle of Thruster Pods--------------------------
- #these 2 lines change the angle of the pods for moving
- GoAngle=40*(S-W)
- TurnAngle=20*(D-A)
- #These next 3 lines put all of the requred calculations that can be changed by the pods'
- #angles (like turning and forward/backward movement and counter movment)
- RPitch=clamp(RPod:angles():pitch()+GoAngle+TurnAngle+SpeedCounter+SpinCounter,-160,160)
- LPitch=clamp(LPod:angles():pitch()+GoAngle-TurnAngle+SpeedCounter-SpinCounter,-160,160)
- APitch=clamp(APod:angles():pitch()+GoAngle+SpeedCounter,-160,160)
- #Then use applyAngForce to change the angle of the pods in only the Pitch
- RPod:applyAngForce(ang(RPitch+$RPitch*4,0,0)*Torque)
- LPod:applyAngForce(ang(LPitch+$LPitch*4,0,0)*Torque)
- APod:applyAngForce(ang(APitch+$APitch*4,0,0)*Torque)
- #}
- #else{
- #The rest of this junk just makes the thrusters level with the craft when turned off
- # RPitch=RPod:angles():pitch()
- # LPitch=LPod:angles():pitch()
- # APitch=APod:angles():pitch()
- # RPod:applyAngForce(ang(RPitch+$RPitch*4,0,0)*20)
- # LPod:applyAngForce(ang(LPitch+$LPitch*4,0,0)*20)
- # APod:applyAngForce(ang(APitch+$APitch*4,0,0)*20)
- # RThrust=0
- # LThrust=0
- # AThrust=0
- #}
- #original code credited to mike_dude
Add Comment
Please, Sign In to add comment