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 Universal - Universal E2 mouseaimed flight

MrStumpMrStump Registered Posts: 24
edited June 2011 in Showcase #1
WHAT IS IT: All e2 (no gyro) mouse aimed flight for any small-medium sized 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 want to add an easy way to remap the controls without digging into the meat of the code. Also add some more tweekable variables (like making space make the ship go up relative to its up, not the worlds).

CURRENT RELEASE: Version 1.3

It took me quite some time to finally settle on this method for mouse-aimed flight. Without an eyepod, this was the only way I could think of to make it happen. I decided to share it with everyone by making it as easy to learn to set up as possible.

VERSION CHANGES:
1.2->1.3
    Switched to setAngVel for aiming (yes, I did it!) Changed turn-strength variable2 into 1 variable due to turning type change Added a bit in the comments about how to possibly fix aim wobbles Minor performance changes
1.1->1.2
    Cut interval in 1/5 Added 2 more variables to tweek turn speed if its jerky (depend son ship shape/size) Overall reduced impact on server significantly
1.0->1.1
    Changed instructions to simplify (good note Kate) Improved Ejector Code
@name Starflight Universal - by MrStump v1.3
@inputs [Pod Cam]:wirelink
@persist Active ViewPause Speed LockChair TurnMult
@persist Step1 Step2 Step3
@outputs [Ship Chair Driver]:entity
@persist [ShipDest CamPos1 CamPos2]:vector
interval(50)

##############################################################
############### Starflight Universal Use Guide ###############
######################### By:MrStump #########################
#                                                            #
# INSTRUCTIONS FOR USE:                                      #
# 1)Spawn a 2x2 holo sphere (shell) from Miscellaneous Props #
# 2)Place sphere in middle of your ship(do not weld yet)     #
# 3)Attach this e2 to it and follow the instructions in chat #
# 4)When finished, alter variables below to fit your ship    #
# 5)After parenting, unfreeze all props but the sphere       #
#                                                            #
# 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 2x2 holo sphere is used as a flight gyro. A spacebuild #
# chair is then placed into the sphere by the e2, and moved  #
# around with the sphere. This unattached nature of the      #
# chair allows for real mouseaim flight. The sphere moves    #
# the ship around it like a pivot point. Make note this e2   #
# does no parenting, use a seperate E2 for that.             #
#                                                            #
# COMMON ISSUE:                                              #
# If the ship wobbles, it is because the sphere is not       #
# strong enough to make it point correctly. You may be able  #
# to fix it by redistributing/lessening weight and moving    #
# the sphere to your ship's center, but there is only so     #
# much total mass the sphere can move. In that case, use the #
# gyropod (intergalactic) version of this E2.                #
#                                                            #
##############################################################
# WARNING: May work on larger ships, but is not recommended! #
##############################################################
##############################################################

############################################################################################
######## Editable Variables ################################################################
if(first()|dupefinished()){
    Speed       = 65             #Determines speed, 45 by default
    LockChair   = 1              #Ejects non-owner from the chair. 1 is on, 0 is off. 1 by default.
    TurnMult    = 5              #Strength of the turning code. Default is 5-8
    CamPos1     = vec(80,0,0)    #Default camera position, or selectable with scroll wheel up
    CamPos2     = vec(-600,0,60) #Secondary camera position, selectable with scrollwheel down
    #NOTE: CamPos1 and CamPos2 are relative to the position of the sphere
}
###### 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(dupefinished()){
    Ship = entity():isWeldedTo()
    Chair = Pod["Entity",entity]
    Ship:setMass(50000)
    Chair:freeze()
    Chair:setAng(ang(0,Ship:angles():yaw(),0))
    ShipDest = Ship:pos()
    Ship:setAlpha(0)
    entity():setAlpha(1)
    Step1 = 0
    Step2 = 0
    Step3 = 0
    Step4 = 0
    Step4 = 1
    holoCreate(1,   Ship:pos(), vec(1,1,1), Ship:angles())
    holoModel(1,    "models/hunter/misc/sphere2x2.mdl")
    holoMaterial(1, "phoenix_storms/stripes")
    holoColor(1,    vec(71,30,20))
    holoParent(1,   Ship)
}

if(first()){
    Ship = entity():isWeldedTo()
    
    if(Ship:model()=="models/hunter/misc/shell2x2.mdl"){
        print("STEP1) Align the sphere so the red arrow points forward and the blue arrow points up then weld sphere to your ship.")
        holoCreate(1, Ship:toWorld(vec(60,0,0)), vec(3,3,3), Ship:toWorld(ang(90,0,0)), vec(255,0,0))
        holoModel(1, "cone")
        holoCreate(2, Ship:toWorld(vec(0,0,60)), vec(3,3,3), Ship:toWorld(ang( 0,0,0)), vec(0,0,255))
        holoModel(2, "cone")
        holoParent(1, entity())
        holoParent(2, entity())
        Ship:setMass(50000)
    }
    else{
        print("SETUP ERROR: You are not attaching the E2 to the correct prop.
        It MUST be attachedto prop models/hunter/misc/shell2x2.mdl,
        which is the holo sphere found in Miscellaneous Props.")
        print("Delete this E2 and try again")
    } 
    
    Step1 = 1
    Step2 = 0
    Step3 = 0
    Step4 = 0
    
}

if(Step1){
    if(Ship:hasConstraints()>1){
        print("STEP2) Spawn a chair (spacebuild Promethius Chair recommended). DO NOT WELD OR NOCOLLID ANYTHING TO/WITH CHAIR!")
        print("STEP3) Spawn an ADV POD CONTROLLER and CAM CONTROLLER, link both to chair.")
        print("STEP4) Wirelink this E2's coresponding wirelinks to Pod controller and Cam controller")
        holoDelete(1)
        holoDelete(2)
        Step1=0
        Step2=1
        
    }
}
if(Step2){
    if(->Cam & ->Pod){
        Chair = Pod["Entity",entity]
        if(Chair:model()==""){
            print("ERROR: You forgot to link the Pod Controller to the chair! Do so now and then repaste this e2")
            Step2 = 0
        }
        else{
            print("STEP5) Use a parenting E2 to parent the rest of your ship TO THE SPHERE. That's it, you're done!")
            print("REMINDER: When you go to dupe your ship, you must remember to dupe both the chair and the ship together because the chair is unconnected to the ship")
            Step2=0
            Step3=1
            Chair:setAng(ang(0,Ship:angles():yaw(),0))
            Chair:freeze()
            ShipDest = Ship:pos()
            Ship:setAlpha(0)
            entity():setAlpha(1)
            
            holoCreate(1,   Ship:pos(), vec(1,1,1), Ship:angles())
            holoModel(1,    "models/hunter/misc/sphere2x2.mdl")
            holoMaterial(1, "phoenix_storms/stripes")
            holoColor(1,    vec(71,30,20))
            holoParent(1,   Ship)
        }
    }
}

if(Step3){
    Active  = Pod["Active",number]
    ShipPos = Ship:pos()
    
    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){
            if(LockChair){ 
                Driver = Chair:driver()
                if(Driver!=owner()){
                    Pod["Eject",number] = 1
                }
                else{
                    ShipDest = ShipPos
                    Chair:propNotSolid(1)
                    Chair:propFreeze(1)
                    Cam["Activated",number] = 1
                }
            }
            else{
                ShipDest = ShipPos
                Chair:propNotSolid(1)
                Chair:propFreeze(1)
                Cam["Activated",number] = 1
            }
            Cam["Position",vector] = Ship:toWorld(CamPos1)
            Cam["Direction",vector] = Ship:forward()
            Cam["Parent",entity] = Ship
            
            timer("ViewPause",1500)
        }
        if(clk("ViewPause")){ViewPause=1 Ship:propFreeze(0)}
        
        DriverEye = Driver:eye()
        
        Cam["Direction",vector] = DriverEye
        
        if(W)            {ShipDest += DriverEye:rotate(ang(0,  0,0))*Speed*(1+Shift*2)}
        if(S)            {ShipDest +=-DriverEye:rotate(ang(0,  0,0))*Speed*(1+Shift*2)}
        if(A)            {ShipDest += DriverEye:rotate(ang(0, 90,0)):setZ(0)*Speed*(1+Shift*2)}
        if(D)            {ShipDest += DriverEye:rotate(ang(0,-90,0)):setZ(0)*Speed*(1+Shift*2)}
        if(Space)        {ShipDest += vec(0,0, Speed)}
        if(Alt)          {ShipDest += vec(0,0,-Speed)}
        if(PrevWeapon)   {Cam["Position",vector] = Ship:toWorld(CamPos1)}
        if(NextWeapon)   {Cam["Position",vector] = Ship:toWorld(CamPos2)}
        
        Vec = ShipDest - ShipPos
        Ship:setVel(Vec*3)
        
        if(ViewPause){ DistViewPos = Chair:toWorld(Chair:toLocalAxis(DriverEye)*5000) }
        else{ DistViewPos = Chair:toWorld(Chair:forward()*5000) }
        ANG  = -Ship:heading(DistViewPos)
        Ship:setAngVel( shiftR(ANG:setRoll(-Ship:angles():roll()))*8 )
    }
    elseif($Active){
        Ship:propFreeze(1)
        Pod["Eject",number] = 0
        Cam["Activated",number] = 0
        Chair:propNotSolid(0)
        Chair:setAng(ang(0,Ship:angles():yaw(),0))
        ViewPause = 0
        ShipLockon = 0
    }
    
    Chair:reposition(Ship:toWorld(-vec(0,0,30)))
}

Comments

  • MikhailMikhail Registered Posts: 24
    I remember seeing you work on this on your little shuttle.
    monkeyk.jpg
  • KatelynKatelyn Registered, Administrator Posts: 171
    Good work, but the set up seems very lengthy.
  • Lambda217Lambda217 Registered, Moderator Posts: 534
    I can see this becoming standard like Taco's LS chip! Does it still move so fast it's virtually unhittable by anything but drones?


    "I want you to show this world what it means to fear the sky."
  • MrStumpMrStump Registered Posts: 24
    So is wiring a gyropod for the first time kate. You spawn 2 things, put on a pod controller and cam controller, link them to 1 of the things, and wirelink the 2 things... I really can't make FLYING THROUGH THE SPACE SPACE LIKE A MAGICAL UNICORN ANY MORE SIMPLE with mouseaim flight involved anyway. And just like a gyro, you only need to put it into your ship once and now your ship flies. This system dupes (and doesn't spam your chat when it dupes with all the instructions). I may simplify it so you spawn a chair, make cam/pod and link both to chair, then wirelink them both tho to save on steps

    And while its possible to fly that fast, the faster you go, the more un-recoverable it is when you DO hit something. No matter how I code it people will fuck with it to let themselves go at high speeds... just like they do with the sneaky way to make gyros go very quickly. The default speed is about fighter speed, but not unhittable or faster than things like drones.

    Also, I'm fiddling with getting better op performance ATM without losing ship performance. That'll be V1.1

    EDIT: Finished 1.1, but I can't lower ops without losing turning performance. So I am considering making a gyropod version of this e2. It would work the same way except use Gyropod for all maneuvering/flight. THOUGHTS?
  • BaltazarBaltazar Registered Posts: 1
    Stump you did it again! I love this chip! thank you soo much!
  • KatelynKatelyn Registered, Administrator Posts: 171
    MrStump wrote:
    So is wiring a gyropod for the first time kate. You spawn 2 things, put on a pod controller and cam controller, link them to 1 of the things, and wirelink the 2 things... I really can't make FLYING THROUGH THE SPACE SPACE LIKE A MAGICAL UNICORN ANY MORE SIMPLE with mouseaim flight involved anyway. And just like a gyro, you only need to put it into your ship once and now your ship flies.

    Right, however you should look into my code that I made for the ship camera. You could remove the cam controller completely from the system, you have my permission to use any code in that as your own. I didn't intend to abase your chip or anything, I only meant to suggest that in future versions you may want to work on the initial set up more in terms of simplifying it if possible. It really looks like good work, I haven't had the chance to use it yet as I am taking a break from gmod.

    As for using a gyropod with it, that is really up to you. What are the ops running at generally? If it is an issue, then maybe you might consider it.
  • MrStumpMrStump Registered Posts: 24
    I am working on the gyropod version now. If nothing else I realized it'll be useful for larger ships. And this version uses a higher interval than I would like. With the gyro I can use 50-100 and not get poor turning/facing.

    As for the camera, I looked through the code and its some nice work, but I am trying to lowball ops as much as possible, and for that its better for me to use a cam controller. Simpler would be better for me generally, but in this case I want to just keep it as-is.
  • Nielk1Nielk1 Registered, Administrator Posts: 252
    There need to be more E2 functions that spawn entities that do side work...
    Would help opp-counts immensely.

    Imagine:
    targetFinderCreate(N)
    targetFinder<Setting>(<PARAMS>)
    targetFinderParent(N,entity())

    Throw in some custom runOnTargetFinder(N) or wire to it by E2 and walla.
    Not picture that with a camera pod controller or HUD controller.

    It would make all in 1 E2s like this one so much faster.
  • Lambda217Lambda217 Registered, Moderator Posts: 534
    Something like Starfall would be more efficent, though.


    "I want you to show this world what it means to fear the sky."
  • slayer123456493slayer123456493 Registered Posts: 25
    im a little confused about the prop you spawn. i spawned a 2x2 shell ball prop but theyre were no arrows on it before or after i put the e2 on it. am i spawning the right prop?
  • MrStumpMrStump Registered Posts: 24
    If the message pops up after ypu place the e2 telling you to use the arrows and u don't see them, its most likely because your holo models are out of date. Update wire and wiremodels svns
  • slayer123456493slayer123456493 Registered Posts: 25
    thanks, wire had been telling me to update but i thought it was just some fixes for things i dont use lol
  • MrStumpMrStump Registered Posts: 24
    I DID IT! I made setAngVel work! I finally fucking reached that summit!

    Well, I'm not sure what else I can add/remove from this e2. "The Wobbles" situation that happens on larger/heavier ships with a bunch of non-evenly distributed weight... well... unless I learn quats I do not believe that I can solve that issue. If you jam 100 tons of shit into the back of your plane, it'll fly shitty. SUPRISE.
  • KanzukeKanzuke Registered, Moderator Posts: 181
    MrStump wrote:
    I DID IT! I made setAngVel work! I finally fucking reached that summit!

    Well, I'm not sure what else I can add/remove from this e2. "The Wobbles" situation that happens on larger/heavier ships with a bunch of non-evenly distributed weight... well... unless I learn quats I do not believe that I can solve that issue. If you jam 100 tons of shit into the back of your plane, it'll fly shitty. SUPRISE.

    Yeah, I learnt that the hard way...

    Still, the gyro is a good replacement

    Lambda217: oh oh i am kanzuke and i love my little pony and now i'll make all the brandonphysics myself cause i know fuckin everything because now i'll make a big pony fighter drone squad and a big fuckin portal ship and i am a fuckin idiot
  • KatelynKatelyn Registered, Administrator Posts: 171
    MrStump wrote:
    I DID IT! I made setAngVel work! I finally fucking reached that summit!

    Well, I'm not sure what else I can add/remove from this e2. "The Wobbles" situation that happens on larger/heavier ships with a bunch of non-evenly distributed weight... well... unless I learn quats I do not believe that I can solve that issue. If you jam 100 tons of shit into the back of your plane, it'll fly shitty. SUPRISE.
    else{
            print("SETUP ERROR: You are not attaching the E2 to the correct prop.
            It MUST be attachedto prop models/hunter/misc/shell2x2.mdl,
            which is the holo sphere found in Miscellaneous Props.")
            print("Delete this E2 and try again")
        }
    

    Instead of telling them to delete the e2, delete it for them. selfDestruct()
    if(Step1){
        if(Ship:hasConstraints()&gt;1){
            print("STEP2) Spawn a chair (spacebuild Promethius Chair recommended). DO NOT WELD OR NOCOLLID ANYTHING TO/WITH CHAIR!")
            print("STEP3) Spawn an ADV POD CONTROLLER and CAM CONTROLLER, link both to chair.")
            print("STEP4) Wirelink this E2's coresponding wirelinks to Pod controller and Cam controller")
            holoDelete(1)
            holoDelete(2)
            Step1=0
            Step2=1
           
        }
    }
    

    Like I said before, see if you can automate this. Iterate through the contraption and check the type of everything against a pod controller / cam controller.
    if(Step2){
        if(-&gt;Cam & -&gt;Pod){
            Chair = Pod&#91;"Entity",entity&#93;
            if(Chair:model()==""){
                print("ERROR: You forgot to link the Pod Controller to the chair! Do so now and then repaste this e2")
                Step2 = 0
            }
    

    Again, selfDestruct(). This would be a good error checking for the previous step.
    if(W)            {ShipDest += DriverEye:rotate(ang(0,  0,0))*Speed*(1+Shift*2)}
            if(S)            {ShipDest +=-DriverEye:rotate(ang(0,  0,0))*Speed*(1+Shift*2)}
            if(A)            {ShipDest += DriverEye:rotate(ang(0, 90,0)):setZ(0)*Speed*(1+Shift*2)}
            if(D)            {ShipDest += DriverEye:rotate(ang(0,-90,0)):setZ(0)*Speed*(1+Shift*2)}
            if(Space)        {ShipDest += vec(0,0, Speed)}
            if(Alt)          {ShipDest += vec(0,0,-Speed)}
    

    Try this code here. (Wrote this in here, may be too many or too little ()'s

    That may or may not increase the performance.
    ShipDest += (DriverEye:rotate(ang(0, 0, 0)) * (Speed * (1+Shift*2*(W - S))))
    ShipDest += (DriverEye:rotate(ang(0, 90, 0)):setZ(0) * (Speed * (1+Shift*2*(A - D))))
    ShipDest += (ShipDest += vec(0,0, (Speed * (Space - Alt))))
    

    Other than that, quaternions are the next step up.
  • MrStumpMrStump Registered Posts: 24
    haha annnnnnnd pass on quats. Quats move too far into math for my liking. I enjoy coding, not complex spacial mathematics. I decided not to do auto-self-destruct before so that people can share the E2 if they want to by just placing it on the ground. It self destructed if not on the right prop when I first wrote it, but it made it a bitch to give to people (having to spawn it onto a sphere and all or it vanishes). So I decided to give them that message instead.

    I would automate the cam/pod controllers... but I have no way to check if a cam controller is linked to the chair... unless you know of one. With the pod I can check its Entity output... which is why I have them spawn and link the things then wirelink. I can check if the wirelinks are connected and if they are, check if the pod controller is linked... if I could check the cam's link or link via e2, I could automate this for them... this does remind me I also need to include an option to not use a cam controller. But I totally get I could do getConstraints to find if they placed a cam and pod on the ship.

    As for the other code, Fuhr took the server down to work on it I think, but I'll take a good look at when its back up.

    EDIT: Switched code on the dev server. Looks neater in the code but no change in ops so I just reverted to what I'm more comfortable with
  • Lambda217Lambda217 Registered, Moderator Posts: 534
    Was just thinking, the parenting E2 doesn't effect chairs, so you could solve the duping issue by connecting the chair to the ship with a Adv Ballsocket with free movement and no angle limits.


    "I want you to show this world what it means to fear the sky."
  • KatelynKatelyn Registered, Administrator Posts: 171
    In that case how about this.
    Const = entity():getConstraints()
    if (Const:count() == 0)
    {
    don't self destruct here, sharing mode.
    }
    else
    {
    normal code here plus self destruct
    }
    

Leave a Comment

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