Wall cling for Lerk
<div class="IPBDescription">with the recipe</div>Implementation of this idea : <a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=115188&st=0" target="_blank">http://www.unknownworlds.com/ns2/forums/in...115188&st=0</a>
It was very easy to do, so I'll show how to do it, someone could maybe learn something ! Basically I adapted the code from Skulk.lua into
Lerk.lua :
Add the wall sticking range in the variables:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Lerk.kNormalWallWalkRange = 0.2<!--c2--></div><!--ec2-->
Init some variables in Lerk:OnInit(), self.wallWalking will tell you if you're attached to the wall:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->self.wallWalking = false
self.wallWalkingNormalCurrent = Vector.yAxis
self.wallWalkingNormalGoal = Vector.yAxis<!--c2--></div><!--ec2-->
Copy two functions that allows to check if you are close to a wall a gives you back the wall orientation :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Lerk:TraceWallNormal(startPoint, endPoint, normals)
...
function Lerk:GetAverageWallWalkingNormal(extraRange)
...<!--c2--></div><!--ec2-->
Then in Lerk:PreUpdateMove call this function to check if you are close to the wall, and set wallWalking to true if so :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if not self:GetIsOnGround() then
local goal = self:GetAverageWallWalkingNormal(Lerk.kNormalWallWalkRange)
if goal ~= nil then
self.wallWalkingNormalGoal = goal
self.wallWalking = true
else
self.wallWalking = false
end
end<!--c2--></div><!--ec2-->
Put the gravity to zero if attached to the wall in Lerk:AdjustGravityForce(input, gravity) :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if self.wallWalking then
return 0
end<!--c2--></div><!--ec2-->
Increase the friction if attached to the wall in Lerk:GetFrictionForce(input, velocity),
so you don't slide too much on the wall :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if self.wallWalking then
frictionScalar = 4
return Vector(-velocity.x, -velocity.y, -velocity.z) * frictionScalar
end<!--c2--></div><!--ec2-->
That's it !
In addition one could add some crouch key condition for attaching to the wall using self.crouching. Also a condition on the speed and the angle you hit the wall would be nice. One can play with the view tilt as well.
Mod in the attachment, "blabla.. steamapps\common\natural selection 2\NS2.exe" -game LerkCling to launch. Comment and suggestions.
<center><object width="450" height="356"><param name="movie" value="http://www.youtube.com/v/mfFKXm8OnKM"></param><embed src="http://www.youtube.com/v/mfFKXm8OnKM" type="application/x-shockwave-flash" width="450" height="356"></embed></object></center>
Zip file : <a href="http://www.unknownworlds.com/ns2/forums/index.php?act=attach&type=post&id=36029" target="_blank">http://www.unknownworlds.com/ns2/forums/in...st&id=36029</a>
It was very easy to do, so I'll show how to do it, someone could maybe learn something ! Basically I adapted the code from Skulk.lua into
Lerk.lua :
Add the wall sticking range in the variables:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Lerk.kNormalWallWalkRange = 0.2<!--c2--></div><!--ec2-->
Init some variables in Lerk:OnInit(), self.wallWalking will tell you if you're attached to the wall:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->self.wallWalking = false
self.wallWalkingNormalCurrent = Vector.yAxis
self.wallWalkingNormalGoal = Vector.yAxis<!--c2--></div><!--ec2-->
Copy two functions that allows to check if you are close to a wall a gives you back the wall orientation :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Lerk:TraceWallNormal(startPoint, endPoint, normals)
...
function Lerk:GetAverageWallWalkingNormal(extraRange)
...<!--c2--></div><!--ec2-->
Then in Lerk:PreUpdateMove call this function to check if you are close to the wall, and set wallWalking to true if so :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if not self:GetIsOnGround() then
local goal = self:GetAverageWallWalkingNormal(Lerk.kNormalWallWalkRange)
if goal ~= nil then
self.wallWalkingNormalGoal = goal
self.wallWalking = true
else
self.wallWalking = false
end
end<!--c2--></div><!--ec2-->
Put the gravity to zero if attached to the wall in Lerk:AdjustGravityForce(input, gravity) :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if self.wallWalking then
return 0
end<!--c2--></div><!--ec2-->
Increase the friction if attached to the wall in Lerk:GetFrictionForce(input, velocity),
so you don't slide too much on the wall :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if self.wallWalking then
frictionScalar = 4
return Vector(-velocity.x, -velocity.y, -velocity.z) * frictionScalar
end<!--c2--></div><!--ec2-->
That's it !
In addition one could add some crouch key condition for attaching to the wall using self.crouching. Also a condition on the speed and the angle you hit the wall would be nice. One can play with the view tilt as well.
Mod in the attachment, "blabla.. steamapps\common\natural selection 2\NS2.exe" -game LerkCling to launch. Comment and suggestions.
<center><object width="450" height="356"><param name="movie" value="http://www.youtube.com/v/mfFKXm8OnKM"></param><embed src="http://www.youtube.com/v/mfFKXm8OnKM" type="application/x-shockwave-flash" width="450" height="356"></embed></object></center>
Zip file : <a href="http://www.unknownworlds.com/ns2/forums/index.php?act=attach&type=post&id=36029" target="_blank">http://www.unknownworlds.com/ns2/forums/in...st&id=36029</a>
Comments
Tested and working as intended, good move making him walk really slow on the wall.
But I keep breaking my game when trying to port this to the Gorge >_<
-B1ackSmoke
From the gameplay point of view, I don't think it would change much. It's more something what you would use while waiting of healing than during combat. It could be useful to keep altitude and use it at the right moment to gain speed, but the current flight model do not really allow that.
>But I keep breaking my game when trying to port this to the Gorge >_<
Hum, it should work more or less in the same way I think, what kind of errors do you get ?
type "thirdperson" in the console while cheats are on to see how it looks. Maybe you could just rotate the player model exactly like the view if he is clinged? Would be a bit abrupt without an nice animation but should be fine as a placeholder :)
function Skulk:AdjustModelCoords(modelCoords)
I tried to fix it, it's a bit buggy, and there is no smooth transition, but it looks better. I also added roll and pitch on the model while flying (he goes straight like a tank right now) it makes it look much more organic I think :
<center><object width="450" height="356"><param name="movie" value="http://www.youtube.com/v/VVoNfjj1Bvc"></param><embed src="http://www.youtube.com/v/VVoNfjj1Bvc" type="application/x-shockwave-flash" width="450" height="356"></embed></object></center>
This might make it too easy for lerks to spike spam from dark far away corners though. I know the devs changed his ability to get him more into direct combat and out of vents and at the end of long hallways.
I tried to fix it, it's a bit buggy, and there is no smooth transition, but it looks better. I also added roll and pitch on the model while flying (he goes straight like a tank right now) it makes it look much more organic I think :<!--QuoteEnd--></div><!--QuoteEEnd-->
It looks awesome! good job :)
I've just tested your mod, and I would strongly suggest adding an activate wall cling key (ctrl?). Otherwise it is too easy to stick to walls by accidental. Wall cling could switch off for a short time when the jump key is pressed, to prevent re-sticking.
You can also improve the efficiency of the check by only performing the wall walk check when the key is pressed down.
Can you not set some animation on wallwalking?
Maybe the "glide" animation would fit good
<img src="http://img263.imageshack.us/img263/8664/glidens2.jpg" border="0" class="linked-image" />
For the code to change it, maybe you look into the fade weapon code "Blink_Client" or the fade code itself i have no idea.
but you know the fade shrinks if he use blink, maybe you can use that with position.
oh ehm i guessed you use the wallwalking code for attaching the lerk on a wall:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if self.wallWalking then
return 0
end<!--c2--></div><!--ec2-->
the skulk uses the wallwalking... i try 1 month ago with lerk too and he could stay in air because i used the wallwalking code and change it.
Here I made some changes, I added some conditions on speed and angle to the clinging instead of a key, I works ok, but may need some tweaking :
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if goal ~= nil then
local dot = math.abs(velocity:DotProduct(goal))
local velLength = self:GetVelocity():GetLength()
//never attach at high speed
if velLength < 10 then
if dot > 0.6 then //landing approach is right
self.wallWalkingNormalGoal = goal
self.wallWalking = true
elseif velLength < 4 then
self.wallWalkingNormalGoal = goal
self.wallWalking = true
end
end
end<!--c2--></div><!--ec2-->
I also added a powerful flap that allows to detach from the wall.
<center><object width="450" height="356"><param name="movie" value="http://www.youtube.com/v/yBfxP79fVxE"></param><embed src="http://www.youtube.com/v/yBfxP79fVxE" type="application/x-shockwave-flash" width="450" height="356"></embed></object></center>
Well I should update it for the current build, because the animations are broken now. But I'm not sure it's really useful because it will be probably broken again in next build, so it's a lot of work for not much. Maybe when the mod download will work we could try to play with it.
Well I should update it for the current build, because the animations are broken now. But I'm not sure it's really useful because it will be probably broken again in next build, so it's a lot of work for not much. Maybe when the mod download will work we could try to play with it.<!--QuoteEnd--></div><!--QuoteEEnd-->
Constant update, iterations and fixes are all part of writing code, it helps you write more solid code as well, because you get fed up of editing your stuff when you do it the long way round :)
Keep going, this is a great mod, sure, maybe wait for 190 release before getting it working properly again, but keep up with it :)