Home Showcase
Welcome to the new Diaspora forums, please let us know if you see anything broken! Notice: Some users may need to reupload their avatars due to an issue during forum setup!

Starflight Intergalactic - Universal Gyro mouseaimed flight

MrStumpMrStump Registered Posts: 24
edited June 2011 in Showcase #1
WHAT IS IT: An e2 that uses gyro for mouse aimed flight for any size ship.
HOW TO USE IT: Read the instructions at the start of the e2 and then follow the step-by-step chat instructions.
HOW TO MODIFY IT: There are variables at the top for simple modifications
FUTURE DEVELOPMENT: I need top hear more about people's experience with this. Also, I think increasing e2's mass will prevent it from being un-editable after parenting sometimes, so I have to play with that.

CURRENT RELEASE: Version 1.1

This is the gyro version of my e2 flight system. It runs on fewer ops due to it letting the gyro do all the heavy lifting (literally). Its better for the server, and also more reliable on anything larger than a small frigate or a fighter.

VERSION CHANGES:
1.0->1.1
    Fixed an oversight in the camera position Fixed a mistake in the "disabled eject" mode
@name Starflight Intergalactic - By MrStump 1.1
@inputs [Gyro Pod Cam]:wirelink
@persist LockChair AutoRoll AutoRollMult ThrustLimit ChairHeight
@persist Step1 Step2 Step3 Step4 Active ViewPause ThrustAccel ThrustAccelMult
@persist [Base GyroEnt Chair Driver]:entity
@persist [CamPos1 CamPos2]:vector
@trigger 
@model models/hunter/tubes/circle2x2.mdl

interval(50)

##############################################################
############# Starflight Intergalactic Use Guide #############
######################### By:MrStump #########################
#                                                            #
# INSTRUCTIONS FOR USE:                                      #
# 1)Spawn this e2 where you want your chair to be in ship    #
# 2)Follow in-chat instructions carefully                    #
# 3)Once finished, dupe ship and parent. Edit variables at   #
#   below this textblock to fit desired performance.         #
#                                                            #
# NOTES FOR ADV DUPING:                                      #
# 1)When duping, right click chair first, then hold shift    #
#   and right click the ship. This is required because the   #
#   chair is not attached to the ship in any way.            #
# 2)Parenting after you paste your dupe is recommended for   #
#   best performance.                                        #
#                                                            #
# CONTROLS:                                                  #
# WASD for Forward/StrafeLeft/Back/StrafeRight               #
# Space/Alt for Up/Down (relative to world, no the ship)     #
# Shift for speed boost                                      #
# Scroll Wheel Up/Down toggles betwene cam positions         #
#                                                            #
# HOW IT WORKS:                                              #
# The e2 spawns a disc which your chair will hover over.     #
# The chair is not attached to your ship in any way, which   #
# allows you to have this variety of mouse-aimed flight.     #
#                                                            #
# COMMON ISSUES:                                             #
# PROB) Ship turns too quickly and flips or too slowly       #
# SOLU) Increase/Decrease the pitch/yaw mults below          #
#                                                            #
##############################################################
##############################################################

############################################################################################
######## Editable Variables ################################################################
if(first()|dupefinished()){   
    ChairHeight              = 20               #Height chair hovers over pad. <20 not recommended.
    LockChair                = 1                #Prevents others from sitting in your chair. 1 is on, 0 is off
    CamPos1                  = vec(80,0,40)      #Position of default camera. Based off CHAIR pos
    CamPos2                  = vec(-500,0,-100) #Position of secondary camera. Based off CHAIR pos
    AutoRoll                 = 1                #Anti-Roll code activation. 1 is on.
    AutoRollMult             = 1                #Strength of anti-roll. <1 is weaker, >1 is stronger.
    ThrustLimit              = 14               #Effective top speed. Too high and you can't turn. 14 default.
    ThrustAccelMult          = 2                #Rate of acceleration to top speed. Make even mult of ThrustLimit
    Gyro["MPH Limit",number] = 1000             #Max possible speed. Set high to keep it out of way.
    Gyro["PitchMult",number] = 6                #Speed ship pitches, larget ships need higher numbers
    Gyro["YawMult",number]   = 6                #Speed ship
    #Gyro["RollMult",number] = 1                #Roll mutliplier. Un-needed if you have AutoRoll on.
    entity():setMaterial("spacebuild/SBLight")  #Sets material of the e2 disk. Change or remove as desired
}
###### END Editable Variables ###############################################################
#############################################################################################

###############################################################
# Editing any following code is of course allowed, but not    #
# advised unless you know WTF you are doing. Its your E2 tho  #
###############################################################

if(first()){
    if(entity():hasConstraints()){
        print("STEP1) Spawn a chair and DO NOT attach anything to it or attach it to anything!")
        print("STEP2) Spawn an Adv Gyropod, weld it to your ship (right side up and facing forward), and then wirelink this e2's Gyro to it. DO NOT LINK GYROPOD TO CHAIR")
        Step1 = 1
        Step2 = 0
        Step3 = 0
        Base = entity()
    }
    else{
        print("ERROR: You have to put this e2 onto a ship where you wish the pilot's seat to be.")
    }
}

if(dupefinished()){
    Step1   = 0
    Step2   = 0
    Step3   = 1
    GyroEnt = Gyro:entity()
    Chair   = Pod["Entity",entity]
    Gyro["Freeze",number] = 1
    Chair:propFreeze(1)
    Chair:setAng(ang(0,GyroEnt:angles():yaw(),0))
    Base = entity()
}

if(Step1){
    if(->Gyro){
        GyroEnt = Gyro:entity()
        if(GyroEnt:hasConstraints()){     
            Gyro["Freeze",number] = 1       
            print("STEP3) Spawn and Adv Pod Controller and a Cam Controller")
            print("STEP4) Link them both to the chair")
            print("STEP5) Wirelink Pod and Cam to the Adv Pod Controller and the Cam Controller")
            Step1=0
            Step2=1
        }
        else{
            print("ERROR: You failed to weld your gyropod to your ship. Do so now and repaste this e2")
            Step1=0
        }
    }
}

if(Step2){
    if(->Cam & ->Pod){
        Chair = Pod["Entity",entity]
        if(Chair:model()==""){
            print("ERROR: You did not link the pod controller to the chair! Do so and then repaste e2")
            Step2=0
        }
        else{
            Chair:propFreeze(1)
            Chair:setAng(ang(0,GyroEnt:angles():yaw(),0))
            print("FINISHED! Refer to the comments at the top of the E2 for further notes")
            Step2=0
            Step3=1
        }
    }
}

if(Step3){
    Active  = Pod["Active",number]
    
    if(Active) {
        W          = Pod["W",number]
        A          = Pod["A",number]
        S          = Pod["S",number]
        D          = Pod["D",number]
        Space      = Pod["Space",number]
        Shift      = Pod["Shift",number]
        Alt        = Pod["Alt",number]
        PrevWeapon = Pod["PrevWeapon",number]
        NextWeapon = Pod["NextWeapon",number]
        #Mouse1     = Pod["Mouse1",number]
        #Mouse2     = Pod["Mouse2",number]
        #R          = Pod["R",number]
        #Light      = Pod["Light",number]
        
        if($Active){
            Driver = Chair:driver()
            if(LockChair){ 
                if(Driver!=owner()){
                    Pod["Eject",number] = 1
                }
                else{
                    Chair:propNotSolid(1)
                    Chair:propFreeze(1)
                    Gyro["Activate",number] = 1
                    Gyro["Freeze",number]   = 0
                    Cam["Activated",number] = 1
                    Cam["Position",vector]  = Base:toWorld(CamPos1:rotate(GyroEnt:angles()-Base:angles()))
                    Cam["Direction",vector] = GyroEnt:forward()
                    Cam["Parent",entity]    = GyroEnt
                }
            }
            else{
                Chair:propNotSolid(1)
                Chair:propFreeze(1)
                Gyro["Activate",number] = 1
                Gyro["Freeze",number]   = 0
                Cam["Activated",number] = 1
                Cam["Position",vector]  = Base:toWorld(CamPos1:rotate(GyroEnt:angles()-Base:angles()))
                Cam["Direction",vector] = GyroEnt:forward()
                Cam["Parent",entity]    = GyroEnt
            }
            timer("ViewPause",1500)
        }
        
        DriverEye = Driver:eye()
        DriverEyeAng = DriverEye:toAngle()
        
        
        if(W)            {Gyro["Forward",number]   = 1}    else{Gyro["Forward",number]=0}
        if(S)            {Gyro["Back",number]      = 1}    else{Gyro["Back",number]=0}
        if(A)            {Gyro["MoveLeft",number]  = 1}    else{Gyro["MoveLeft",number]=0}
        if(D)            {Gyro["MoveRight",number] = 1}    else{Gyro["MoveRight",number]=0}
        if(Space)        {Gyro["MoveUp",number]    = 1}    else{Gyro["MoveUp",number]=0}
        if(Alt)          {Gyro["MoveDown",number]  = 1}    else{Gyro["MoveDown",number]=0}
        if(PrevWeapon)   {Cam["Position",vector]   = Base:toWorld(CamPos1:rotate(GyroEnt:angles()-Base:angles()))}
        if(NextWeapon)   {Cam["Position",vector]   = Base:toWorld(CamPos2:rotate(GyroEnt:angles()-Base:angles()))}
        
        
        if(W|A|S|D|Space|Alt){
            if(ThrustAccel<ThrustLimit+(ThrustLimit*Shift)){ThrustAccel += ThrustAccelMult}
            if(ThrustAccel>ThrustLimit+(ThrustLimit*Shift)){ThrustAccel -= ThrustAccelMult}
        }
        else{
            ThrustAccel=0
        }
        Gyro["ThrustMult",number] = ThrustAccel
        
        
        if(AutoRoll){
            GyroRoll = GyroEnt:angles():roll()
            if(GyroRoll != 0){ Gyro["RollLeft",number]  = 1 }    else{ Gyro["RollLeft",number]  = 0 } 
            Gyro["RollMult",number] = GyroRoll/AutoRollMult
        }

        if(clk("ViewPause")){
            ViewPause              = 1
            Gyro["AimMode",number] = 1
        }
        if(ViewPause){
            Gyro["AimVec",vector] = GyroEnt:pos()+DriverEye*5000
            Cam["Direction",vector] = DriverEye
        }

    }
    elseif($Active){
        ViewPause               = 0
        Pod["Eject",number]     = 0
        Cam["Activated",number] = 0
        Gyro["Activate",number] = 0
        Gyro["AimMode",number]  = 0
        Gyro["Freeze",number]   = 1
        Chair:propNotSolid(0)
        Chair:setAng(ang(0,GyroEnt:angles():yaw(),0))
    }
    
    Chair:reposition(Base:toWorld(vec(0,0,ChairHeight)))
}

Comments

  • KatelynKatelyn Registered, Administrator Posts: 171
    I really like how you split it into two separate chips. An idea if you ever want it to be one chip is have it detect a gyropod. If it finds one then turn off the "heavy lifting" as you call it.
  • Lambda217Lambda217 Registered, Moderator Posts: 534
    Quick tip: instead of
    if(W) {Gyro["Forward",number]   = 1}  else {Gyro["Forward",number]=0}
    
    Why not do:
    Gyro["Forward",number] = W
    


    "I want you to show this world what it means to fear the sky."
  • MrStumpMrStump Registered Posts: 24
    Makes sense. Just always did it like this I guess. I'll switch both this and the other code versions over next time I release a version of either

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file