so I wrote some lerk movement code
<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.
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
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).
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.
The system in the code I posted feels better, the more you look down, the less you go up.
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?
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...
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?
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.
<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. =)
<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>