so I wrote some lerk movement code

shad3rshad3r Join Date: 2010-07-28 Member: 73273Members
<div class="IPBDescription">cos the code in the alpha is placeholder</div>I was investigating why lerk movement was off in the alpha, and discovered that the lerk movement code in the current distribution basically says "TODO"

So I wrote some. Seems to work OK.

It's not much, so I'll post it here.

First - Back up the Lerk.lua file. Don't be an idiot like me and edit your only copy.

Now, first we alter some constants and add one. Look for this near the top of the file:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Lerk.kFlapUpImpulse = 6<!--c2--></div><!--ec2-->

change it to this:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Lerk.kFlapUpImpulse = 5
Lerk.kFlapMoveImpulse = 3<!--c2--></div><!--ec2-->

...that's adding an extra line as well as changing a value.

Also,down a few lines change the value of Lerk.kMaxSpeed:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Lerk.kMaxSpeed = 12.0<!--c2--></div><!--ec2-->

... that's increased a lot, but seems to work as I remember lerks working. Current value was way too slow.

Now we alter two functions.

First Lerk:ComputeForwardVelocity(). Replace it with this:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Lerk:ComputeForwardVelocity(input)

    if(self:GetIsOnGround()) then
        return Player.ComputeForwardVelocity(self, input)
    else
    
        // when lerks fly, velocity can only be added via Flapping
        // direction (but not speed) can be changed by this func
        // so calculate our desired velocity,  which is our desired move direction times our current speed
        // and return it MINUS our current velocity
        // - this gives the amount to add to our current velocity to get us moving where we want to go
        local move            = Vector()
        VectorCopy(input.move, move)
        
        // if we are gliding, act as if forward is pressed, if backward isn't
        // (so you move where you're facing)
        if (self.gliding and not (move.z < 0)) then
            move.z = 1
        end
        move:Normalize()
        
        // get our current speed
        local vel             = self:GetVelocity()
        local speed            = vel:GetLength()
        local angles        = Angles(input.pitch + self.basePitch, input.yaw + self.baseYaw, self.baseRoll)  
        local viewCoords    = angles:GetCoords()
        local moveVelocity  = viewCoords:TransformVector( move ) * speed
        
        // subtract our current velocity
        moveVelocity         = moveVelocity - vel
        return moveVelocity
        
    end

end<!--c2--></div><!--ec2-->

Then, Lerk:Flap(). Replace with this

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Lerk:Flap(input, velocity)

    // Thrust any direction TODO: should be able to strafe flap? this allows it
    local angles        = Angles(input.pitch + self.basePitch, input.yaw + self.baseYaw, self.baseRoll)  
    local viewCoords    = angles:GetCoords()
    local moveVelocity  = viewCoords:TransformVector( input.move )
    moveVelocity:Normalize()
    
    // reduce lift when facing down, pressing a move key, and flapping (allows dive bombing and ducking under doors)
    local liftImpulse     = (1 + Clamp( moveVelocity:DotProduct(Vector(0, 1, 0)), -1, 0 )) * Lerk.kFlapUpImpulse
        
    // scale by flap impulse amount
    moveVelocity:Scale( Lerk.kFlapMoveImpulse )
    
    //are we pressing any move keys?
    if(input.move:GetLength() > 0) then
        velocity.x = velocity.x + moveVelocity.x
        velocity.z = velocity.z + moveVelocity.z
        velocity.y = velocity.y + moveVelocity.y + liftImpulse
    else
        velocity.y = velocity.y + Lerk.kFlapStraightUpImpulse
    end

    // Play wing flap sound
    Shared.PlaySound(self, Lerk.kFlapSound)
    
end<!--c2--></div><!--ec2-->

To use it, edit the file, start a server, do "cheats 1" in the console, join aliens, then use "lerk" in the console to evolve to lerk (lerk gets disabled on the evolve menu - I assume cos of a consistency check?)

It's not an attempt to copy NS1. Main change I think is that flapping won't always give you upward lift - upward lift is reduced when you face below horizontal, to none at all for facing straight down. Flapping always accelerates you in the direction you are pressing on the keyboard (even strafing - could you do this in NS1?). The variable lift lets you dive bomb, and also duck through doors. My main memory of NS1 lerk is trying to escape from marines, and getting stuck on the wall just above the door every time cos I flapped too high. WIth this code if you look down a bit you can go fast without going up.

Note to devs: ns2_tram looks great, but all the fancy stuff on the ceilings really makes skulking and lerking hard.

So anyways, how do you make the engine reload a script, without restarting the server?

Apologies for dopey things in the code, I'm a C++ coder and unsure about lua syntax, so I just used really simple constructions that I knew would have to work.

Comments

  • MasterPTGMasterPTG Join Date: 2006-11-30 Member: 58780Members
    edited August 2010
    Has anyone else tried this out? Can anyone upload a video of the lerk with this code? (fraps it or something?). I'd love to see the NS2 lerk actually moving properly...
  • remiremi remedy [blu.knight] Join Date: 2003-11-18 Member: 23112Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester
    <!--quoteo(post=1790342:date=Aug 1 2010, 06:03 AM:name=MasterPTG)--><div class='quotetop'>QUOTE (MasterPTG @ Aug 1 2010, 06:03 AM) <a href="index.php?act=findpost&pid=1790342"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Has anyone else tried this out? Can anyone upload a video of the lerk with this code? (fraps it or something?). I'd love to see the NS2 lerk actually moving properly...<!--QuoteEnd--></div><!--QuoteEEnd-->
    Well in his post he said that his code doesn't actually make it move properly.

    I actually implemented NS1 lerk flight in the engine test, and I'm planning on porting it to the alpha as soon as I stop being lazy (maybe now).
  • remiremi remedy [blu.knight] Join Date: 2003-11-18 Member: 23112Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester
    Just tried out your code, it's a great start. Definitely makes the lerk more maneuverable. I think I'm going to iterate on yours to add in some gliding. ;)
  • That_Annoying_KidThat_Annoying_Kid Sire of Titles Join Date: 2003-03-01 Member: 14175Members, Constellation
    Sweet thread, can't wait to see what is cooked up since I love me some lerking
  • Donner & BlitzenDonner & Blitzen Join Date: 2010-03-08 Member: 70879Members
    Might I suggest that you HOLD the flap key to continue clapping, and you press another key (like shift or ctrl) to glide? I never liked having to repeatedly slam on the spacebar as a Lerk just to get around. That's like pressing "W" for every step you take as a Marine.
  • garvanigarvani Join Date: 2009-09-02 Member: 68678Members
    Im personally opposed too holding a button for rapid fire flapping, i prefer the current method of 1 tap = 1 flap.. far far more control over the lerk this way.. If you need to high tail it out of their you sure as %^#@ start banging away on the keyboard :)
  • shad3rshad3r Join Date: 2010-07-28 Member: 73273Members
    I really like hold flap for glide, I like the rhythm of long presses (flap - glide - flap -glide). I was thinking maybe instead of scaling the lift based on look direction, just have hold crouch to stop lift? That way anytime you hold crouch you just move in the direction you're facing, making it easier to duck under doors (can you tell I had problems with doorways as a lerk?)

    Also I think kFLapStraightUpImpulse needs increasing, you still have to bang the button a bit to get some height when not pressing the movement keys.

    If I had fraps I'd post videos of me doing laps of tram... you can build up quite some speed.
  • shad3rshad3r Join Date: 2010-07-28 Member: 73273Members
    Just tried crouch for stopping lift... didn't like it. Was like "instant drop like a rock mode".
    The system in the code I posted feels better, the more you look down, the less you go up.
  • Donner & BlitzenDonner & Blitzen Join Date: 2010-03-08 Member: 70879Members
    edited August 2010
    <!--quoteo(post=1790631:date=Aug 2 2010, 07:56 AM:name=shad3r)--><div class='quotetop'>QUOTE (shad3r @ Aug 2 2010, 07:56 AM) <a href="index.php?act=findpost&pid=1790631"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Just tried crouch for stopping lift... didn't like it. Was like "instant drop like a rock mode".
    The system in the code I posted feels better, the more you look down, the less you go up.<!--QuoteEnd--></div><!--QuoteEEnd-->

    I don't see the problem with that. What's the difference between that and simply releasing the spacebar?
  • shad3rshad3r Join Date: 2010-07-28 Member: 73273Members
    What's the difference?

    In the code I posted, the variable lift thingy means when you face down (or press crouch in the other option I tried), pressing flap still accelerates you forward, just not up as well. Normal flapping pushes you forward and up. That's why you can't dive in NS1, when you face down your flaps push you down and up at the same time.

    So the difference between that and just not pressing the jump button (mine's RMB, not space) is you still accelerate towards where you want to go.

    Anyways just had a good play with NS1 lerk on a listenserver running ns_nothing. [Man I loved that map. I had more fun playing 1.04 than any game ever. Why no-one plays on NS Australian servers anymore? Australians post here. Let's play!]

    Main difference between the code I posted and NS1 is you can't strafe flap or glide in NS1, you can't dive, and the glide feels different. I couldn't work out how to implement NS1 style glide in NS2 the way the move physics code works at the moment ... NS1 glide seems to allow you to instantaneously change your direction. Oh wait, got an idea...
  • FehaFeha Join Date: 2006-11-16 Member: 58633Members
    edited August 2010
    You should make a limit on how often the lerk can flap, so its something like 3 flaps per second (300 ms delay), cause the lerk just doesnt seem like a humming bird to me (but less would probably mean to low response time as sometimes flapping can be used in a similar manner that birds tilt their wings rapidly to change dir).


    EDIT:
    Also, if you add a delay, and if someone flaped, then quickly repressed and held button, should they be registrated as gliding, or glide until next flap where they would flap, or would they just fall and then at next flap they would flap?
  • ObraxisObraxis Subnautica Animator & Generalist, NS2 Person Join Date: 2004-07-24 Member: 30071Super Administrators, Forum Admins, NS1 Playtester, Forum Moderators, NS2 Developer, Constellation, NS2 Playtester, Squad Five Silver, WC 2013 - Supporter, Subnautica Developer, Pistachionauts
    I wonder if the devs could maybe post up some gameplay LUA that they still need to code, and see if the community can code it for them? Would save time and get the game to us faster! :)
  • twilitebluetwiliteblue bug stalker Join Date: 2003-02-04 Member: 13116Members, NS2 Playtester, Squad Five Blue
    I'm working on modifying Lerk.lua so the Lerk can freelook while gliding. I may need a lot of help here.
  • KoruyoKoruyo AUT Join Date: 2009-06-06 Member: 67724Members, Reinforced - Shadow
    edited January 2011
    Just need to add that @freelook:

    He shouldnt be able to look 360° while gliding(you know wings etc... you cant glide left, right or backwards)... just moving its head somewhere between 90-180° max. id say.
  • twilitebluetwiliteblue bug stalker Join Date: 2003-02-04 Member: 13116Members, NS2 Playtester, Squad Five Blue
    <!--sizeo:3--><span style="font-size:12pt;line-height:100%"><!--/sizeo-->It is ready!<!--sizec--></span><!--/sizec--> The forum Link is below. Please do test it and I look forward to everyone's feedback.
    <a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=112361&view=findpost&p=1824885" target="_blank">http://www.unknownworlds.com/ns2/forums/in...t&p=1824885</a>

    @Koruyo: You can turn at most 88º before the Lerk falls out out of gliding mode. =)
  • twilitebluetwiliteblue bug stalker Join Date: 2003-02-04 Member: 13116Members, NS2 Playtester, Squad Five Blue
    edited January 2011
    Updated: Lerk Mod v. 1.6
    <a href="http://www.mediafire.com/?yz07t4xeyufimpc" target="_blank">http://www.mediafire.com/?yz07t4xeyufimpc</a>

    Lerk Mod v. 1.5a
    <a href="http://www.mediafire.com/?fkgvwk7umy0fqxn" target="_blank">http://www.mediafire.com/?fkgvwk7umy0fqxn</a>
Sign In or Register to comment.