Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31
Like Tree2Likes

Thread: Dynamech

  1. #1
    Wiremode Helper Techni's Avatar
    Join Date
    Jul 2008
    Posts
    968
    Blog Entries
    1

    Default Dynamech

    Garry's Mod - Xfire Video

    I know it's long, but do try to watch the entire vid

    Basically, this is an applyForce/applyTorque mech which introduces a few new ideas to make the movement amazingly smooth and precise without the odd odd walking or sliding I've seen in other applyForce mechs and my own earlier attempts. It uses dynamically generated B?zier curves to ensure smooth paths of any size or distance. This results in very realistic movement (Notice when I grab a leg and tug on it it hobbles and hops to counter-balance) while minimising parts (No hydraulics, elastics etc) and maintains the speed and precision we're used to for E2 mechs. It can run (both feet are off the ground when it's running), but it can be buggy, you can see it running in the sewers.

    Code & Dupe tomorrow

    Any questions?

    E2 code and Dupe below. Controls are W A S D for forwards, backwards and strafing. Shift and R to turn left and right (Soon to be mouse controlled). Hold space to run (Glitchy).

    Code:
    @name Mech v9
    @inputs [Pod Cam Eye]:wirelink [Body Left Right Torso]:entity
    @outputs Ops
    @persist [MechMode StandMode WalkMode LRunMode RRunMode]:string Dir Tilt Bear Elev #Mech General
    @persist Height StrideL StrideH Strafe Width #stand, walk & run constants
    @persist [Start Mid End]:vector T Flip #stand, walk & run variables
    @persist [LStart LMid LEnd RStart RMid REnd]:vector RT LT #RunVariables
    @persist FMod
    @trigger none
    
    #MechModes = stand, walk, run, jump, hover, fly
    #WalkModes = start_calc, left_calc, left_force, right_calc, right_force
    #RunModes = idle, calc, force
    
    
    runOnTick(1)
    
    Ops = ops()
    
    if (first()|dupefinished()) {
    
    MechMode  = "stand"
    WalkMode  = "start_calc"
    StandMode = "start_calc"
    LRunMode  = "idle"
    RRunMode  = "idle"
    
    FMod = 100
    
    Height  = 100
    Strafe  = 100
    StrideL = 350
    StrideH = 30
    Acc     = 0.01
    Dec     = 0.01
    Width = 36
    
    rangerPersist(1)
    findInSphere(Body:pos(),200)
    rangerFilter(findToArray())
    rangerFilter(Left)
    rangerFilter(Right)
    rangerFilter(Body)
    rangerFilter(Torso)
    
    Left:setMass(10000)
    Right:setMass(10000)
    Body:setMass(10000)
    Torso:setMass(10000)
    
    }
    
    W = Pod["W",number]
    A = Pod["A",number]
    S = Pod["S",number]
    D = Pod["D",number]
    Sh = Pod["Shift",number]
    Sp = Pod["Space",number]
    R = Pod["R",number]
    
    EyeV = Pod["XY",vector2]
    
    
    # Left                      #Right                       #Body                       #Torso
    LVel = Left:vel(),          RVel = Right:vel(),          BVel = Body:vel(),          TVel = Torso:vel()
    LMas = Left:mass(),         RMas = Right:mass(),         BMas = Body:mass(),         TMas = Torso:mass()
    LMsc = Left:massCenter(),   RMsc = Right:massCenter(),   BMsc = Body:massCenter(),   TMsc = Torso:massCenter()
    LPos = Left:pos(),          RPos = Right:pos(),          BPos = Body:pos(),          TPos = Torso:pos()
    LQat = quat(Left),          RQat = quat(Right),          BQat = quat(Body),          TQat = quat(Torso)
    LIne = Left:inertia(),      RIne = Right:inertia(),      BIne = Body:inertia(),      TIne = Torso:inertia()
    LAve = Left:angVelVector(), RAve = Right:angVelVector(), BAve = Body:angVelVector(), TAve = Torso:angVelVector()
    LRgt = Left:right(),        RRgt = Right:right(),        BRgt = Body:right(),        TRgt = Torso:right()
    LFwd = Left:forward(),      RFwd = Right:forward(),      BFwd = Body:forward(),      TFwd = Torso:forward()
    LUpd = Left:up(),           RUpd = Right:up(),           BUpd = Body:up(),           TUpd = Torso:up()
    
    
    if (Sp) {
        MechMode = "run"
        StandMode = "start_calc"
        WalkMode = "start_calc"
    }elseif (W|S|A|D) {
        MechMode = "walk"
        StandMode = "start_calc"
        WalkMode = WalkMode
        LRunMode = "idle"
        RRunMode = "idle"
    }else{
        MechMode = "stand"
        StandMode = StandMode
        WalkMode = "start_calc"
        LRunMode = "idle"
        RRunMode = "idle"
    }
    
    
    Dir+=(Sh-R)*(Sp ? 0.3 : 0.8)
    
    if (MechMode == "walk"|MechMode == "stand"|MechMode == "run") {
        BForce = (LMsc+RMsc)/2 + vec(0,0,Height) - BMsc
        BDesQuat = qRotation(vec(0,0,1),Dir)
        BTorque = Body:toLocal(rotationVector(BDesQuat/BQat) + BPos)
        
        Body:applyForce(BForce*BMas*FMod - BVel*BMas)
        Body:applyTorque(BTorque*BIne*1000 - BAve*BIne*20)
        
        LTorque = Left:toLocal(rotationVector(qRotation(vec(0,0,1),Dir)/LQat) + LPos)
        RTorque = Right:toLocal(rotationVector(qRotation(vec(0,0,1),Dir)/RQat) + RPos)
            
        Left:applyTorque(LTorque*LIne*1000 - LAve*LIne*20)
        Right:applyTorque(RTorque*RIne*1000 - RAve*RIne*20)
    }
    
    if (MechMode == "walk") {
        if (WalkMode == "start_calc") {
            WalkMode = (randint(2) == 2 ? "right_calc" : "left_calc")
        }
        
        if (WalkMode == "left_calc") {
            Start = LMsc
            End = BMsc + vec(0,0,-Height) + BFwd * (StrideL/2)*(W-S) + BRgt*( (Strafe/2)*(D-A) - Width )
            Mid = (Start+End)/2 + vec(0,0,StrideH*2)
            
            T = 0
            WalkMode = "left_force"
        }
        
        if (WalkMode == "right_calc") {
            Start = RMsc
            End = BMsc + vec(0,0,-Height) + BFwd * (StrideL/2)*(W-S) + BRgt*( (Strafe/2)*(D-A) + Width )
            Mid = (Start+End)/2 + vec(0,0,StrideH*2)
            
            T = 0
            WalkMode = "right_force"
        }
    
        if (WalkMode == "left_force") {
            LDesPos = mix(mix(End,Mid,T),mix(Mid,Start,T),T)
            
            RD = rangerOffsetHull(99999,LDesPos+vec(0,0,StrideH),vec(0,0,-1),vec(24,24,2))
            LForce = LDesPos:setZ( RD:position():z() + (LDesPos:z()-End:z()) ) - LMsc
            
            Snap = (RD:distance() < StrideH*3.5 ? 0.5 : 0)
            Left:applyForce((LForce:setZ(LForce:z() <0 ? LForce:z()*Snap : LForce:z()))*LMas*FMod - LVel:setZ(LVel:z() <0 ? LVel:z()*Snap : LVel:z())*LMas)
            Right:applyForce( -RVel:setZ(RVel:z() <0 ? 0 : RVel:z())*RMas)
            
            if ((T >= 0.5 & rangerOffsetHull(LMsc,LMsc,vec(24,24,6)):hit()) ) {WalkMode = "right_calc"}
            if (T > 1) {WalkMode = "right_calc"}
            
            T+= 0.04
        }
        
        if (WalkMode == "right_force") {
            RDesPos = mix(mix(End,Mid,T),mix(Mid,Start,T),T)
            
            RD = rangerOffsetHull(99999,RDesPos+vec(0,0,StrideH),vec(0,0,-1),vec(24,24,2))
            RForce = RDesPos:setZ(RD:position():z()+ (RDesPos:z()-End:z())) - RMsc
            
            Snap = (RD:distance() < StrideH*3.5 ? 0.5 : 0)
            Right:applyForce((RForce:setZ(RForce:z() <0 ? RForce:z()*Snap : RForce:z()))*RMas*FMod - RVel:setZ(RVel:z() <0 ? RVel:z()*Snap : RVel:z())*RMas)
            Left:applyForce(  -LVel:setZ( LVel:z() <0 ? 0 : LVel:z() )*LMas)
            
            if ((T >= 0.5 & rangerOffsetHull(RMsc,RMsc,vec(24,24,6)):hit()) ) {WalkMode = "left_calc"}
            if (T > 1) {WalkMode = "left_calc"}
            
            T+= 0.04
        }
    }
    
    if (MechMode == "stand") {
        if (StandMode == "start_calc") {
            if (RMsc:distance(BMsc - vec(0,0,Height) + BRgt*Width) > 30 & Flip) {
                Flip = 0
                Start = RMsc
                End = BMsc - vec(0,0,Height) + BRgt*Width
                Mid = (Start+End)/2 + vec(0,0,StrideH*2)
                
                StandMode = "right_force"
                T = 0
            }elseif (LMsc:distance(BMsc - vec(0,0,Height) - BRgt*Width) > 30) {
                Flip = 1
                Start = LMsc
                End = BMsc - vec(0,0,Height) - BRgt*Width
                Mid = (Start+End)/2 + vec(0,0,StrideH*2)
                
                StandMode = "left_force"
                T = 0
            }else{
                Left:applyForce(  -LVel:setZ(LVel:z() < 0 ? 0 : LVel:z()) * LMas)
                Right:applyForce( -RVel:setZ(RVel:z() < 0 ? 0 : RVel:z()) * RMas)
            }
        }
            
        if (StandMode == "left_force") {
            LDesPos = mix(mix(End,Mid,T),mix(Mid,Start,T),T)
            
            RD = rangerOffsetHull(99999,LDesPos+vec(0,0,StrideH),vec(0,0,-1),vec(24,24,2))
            LForce = LDesPos:setZ( RD:position():z() + (LDesPos:z()-End:z()) ) - LMsc
            
            Snap = (RD:distance() < StrideH*3.5 ? 0.5 : 0)
            Left:applyForce((LForce:setZ(LForce:z() <0 ? LForce:z()*Snap : LForce:z()))*LMas*FMod - LVel:setZ(LVel:z() <0 ? LVel:z()*Snap : LVel:z())*LMas)
            Right:applyForce( -RVel:setZ(RVel:z() <0 ? 0 : RVel:z())*RMas)
            
            if ((T >= 0.5 & rangerOffsetHull(LMsc,LMsc,vec(24,24,6)):hit()) ) {StandMode = "start_calc"}
            if (T > 1) {StandMode = "start_calc"}
            
            T+= 0.04
        }
        
        if (StandMode == "right_force") {
            RDesPos = mix(mix(End,Mid,T),mix(Mid,Start,T),T)
            
            RD = rangerOffsetHull(99999,RDesPos+vec(0,0,StrideH),vec(0,0,-1),vec(24,24,2))
            RForce = RDesPos:setZ(RD:position():z()+ (RDesPos:z()-End:z())) - RMsc
            
            Snap = (RD:distance() < StrideH*3.5 ? 0.5 : 0)
            Right:applyForce((RForce:setZ(RForce:z() <0 ? RForce:z()*Snap : RForce:z()))*RMas*FMod - RVel:setZ(RVel:z() <0 ? RVel:z()*Snap : RVel:z())*RMas)
            Left:applyForce(  -LVel:setZ( LVel:z() <0 ? 0 : LVel:z() )*LMas)
            
            if ((T >= 0.5 & rangerOffsetHull(RMsc,RMsc,vec(24,24,6)):hit()) ) {StandMode = "start_calc"}
            if (T > 1) {StandMode = "start_calc"}
            
            T+= 0.04
        }
    }
    
    if (MechMode == "run") {
        if (LRunMode == "idle" & RRunMode == "idle") {
            if (1) {RRunMode = "calc"}else{LRunMode == "calc"}
        }
        if (LRunMode == "calc") {
            LStart = LMsc
            LEnd = BMsc + vec(0,0,-Height) + BFwd * (StrideL/1.1)*(W-S) + BRgt*( (Strafe/1.1)*(D-A) - Width )
            LMid = (LStart+LEnd)/2 + vec(0,0,StrideH*2)
            
            LT = 0
            LRunMode = "force"
        }
        
        if (RRunMode == "calc") {
            RStart = RMsc
            REnd = BMsc + vec(0,0,-Height) + BFwd * (StrideL/1.1)*(W-S) + BRgt*( (Strafe/1.1)*(D-A) + Width )
            RMid = (RStart+REnd)/2 + vec(0,0,StrideH*2)
            
            RT = 0
            RRunMode = "force"
        }
        
        if (LRunMode == "idle") {
            Left:applyForce(  -LVel:setZ( LVel:z() <0 ? 0 : LVel:z() )*LMas)
        }
        if (RRunMode == "idle") {
            Right:applyForce( -RVel:setZ(RVel:z() <0 ? 0 : RVel:z())*RMas)
        }
        
        if (LRunMode == "force") {
        
            LDesPos = mix(mix(LEnd,LMid,LT),mix(LMid,LStart,LT),LT)
            
            RD = rangerOffsetHull(99999,LDesPos+vec(0,0,StrideH),vec(0,0,-1),vec(24,24,2))
            LForce = LDesPos:setZ( RD:position():z() + (LDesPos:z()-LEnd:z()) ) - LMsc
            
            Snap = (RD:distance() < StrideH*3.5 ? 0.5 : 0)
            Left:applyForce((LForce:setZ(LForce:z() <0 ? LForce:z()*Snap : LForce:z()))*LMas*FMod - LVel:setZ(LVel:z() <0 ? LVel:z()*Snap : LVel:z())*LMas)
            
            if ((LT > 0.5 & rangerOffsetHull(LMsc,LMsc,vec(24,24,6)):hit()) ) {LRunMode = "idle"}
            if (LT > 1) {LRunMode = "idle"}
            if (LT > 0.75 & RRunMode == "idle") {RRunMode = "calc"}
            
            LT+= 0.05
        }
        
        if (RRunMode == "force") {
            RDesPos = mix(mix(REnd,RMid,RT),mix(RMid,RStart,RT),RT)
            
            RD = rangerOffsetHull(99999,RDesPos+vec(0,0,StrideH),vec(0,0,-1),vec(24,24,2))
            RForce = RDesPos:setZ(RD:position():z()+ (RDesPos:z()-REnd:z())) - RMsc
            
            Snap = (RD:distance() < StrideH*3.5 ? 0.5 : 0)
            Right:applyForce((RForce:setZ(RForce:z() <0 ? RForce:z()*Snap : RForce:z()))*RMas*FMod - RVel:setZ(RVel:z() <0 ? RVel:z()*Snap : RVel:z())*RMas)
            
            if ((RT > 0.5 & rangerOffsetHull(RMsc,RMsc,vec(24,24,6)):hit()) ) {RRunMode = "idle"}
            if (RT > 1) {RRunMode = "idle"}
            if (RT > 0.75 & LRunMode == "idle") {LRunMode = "calc"}
            
            RT+= 0.05
        }
        
    }
    Attached Files Attached Files
    Last edited by Techni; 10-10-2010 at 08:06 AM. Reason: Dupe + E2
    miojox and Griba like this.

  2. #2
    Wirererer crichards's Avatar
    Join Date
    Aug 2010
    Location
    NC
    Posts
    293

    Default Re: Dynamech

    Just one:
    Will you marry me?

    In all seriousness, I'm a huge fan of what you do.

  3. #3
    Wire Amateur legolas1042's Avatar
    Join Date
    Jun 2009
    Location
    under a rock
    Posts
    74

    Default Re: Dynamech

    that video, I wanted to flag it as inappropriate... inappropriately awesome
    oh questions?
    Mr. Techni any chance you're going to re-create the works of this epic genius? http://www.ted.com/talks/theo_jansen_creates_new_creatures.html

  4. #4
    Wirererer crichards's Avatar
    Join Date
    Aug 2010
    Location
    NC
    Posts
    293

    Default Re: Dynamech

    lmao.
    Imagining that guy with a physgun in his hands, dragging plastic tubes and lemonade bottles across the beach.

  5. #5
    Developer Jack37's Avatar
    Join Date
    Jul 2009
    Location
    Slovakia
    Posts
    1,311

    Default Re: Dynamech

    Awesome work. Sad I can't give you +rep

    Only the small secrets need to be protected. The big ones are kept secret by public incredulity.

  6. #6
    Wiremode Helper Techni's Avatar
    Join Date
    Jul 2008
    Posts
    968
    Blog Entries
    1

    Default Re: Dynamech

    Quote Originally Posted by legolas1042 View Post
    that video, I wanted to flag it as inappropriate... inappropriately awesome
    oh questions?
    Mr. Techni any chance you're going to re-create the works of this epic genius?Theo Jansen creates new creatures | Video on TED.com
    Those contraptions are... amazing, but no, I wasn't trying to create something like that, rather, just a generic base for a Mech which isn't glitchy, snappy, slidy and is all terrain.

  7. #7
    Wiremode Helper Techni's Avatar
    Join Date
    Jul 2008
    Posts
    968
    Blog Entries
    1

    Default Re: Dynamech

    OP Updated with Dupe and E2

  8. #8
    Wire Noob HavocMan's Avatar
    Join Date
    Feb 2010
    Posts
    10

    Default Re: Dynamech

    I have to say nice job! I make some mechs too but i'm not good enough with e2 to make the chip. I always use hip based movement xD. Good work, hope to see you decorate it!

  9. #9
    Wire Noob Falk's Avatar
    Join Date
    Sep 2010
    Posts
    19

    Default Re: Dynamech

    downloaded, and it's awsome...

  10. #10
    Wirererer adeeda's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    135

    Default Re: Dynamech

    Incredible! Do you plan to add the ability for it to fall? It looked like it didn't handle falling off that prop very well :P

    Also, I loved how you could drag it places, but when you turned it, it snapped back to it's original angle. Will you make it free to turn like it is free to move?
    Anne drew Andrew and Drew, and Druanne drew Anne, Drew, Andrew, and Ru.
    AnDrEw in-game.

Page 1 of 4 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
unnecessary
unnecessary
unnecessary
unnecessary
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots