Lerk Free Aim

Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
edited February 2012 in Modding
There was a request made in Agiel's Free-Aim mod to make the free-aim ability available for the lerk. I have coded it, using the base of Agiel's mod.

<u>*Updated to Version 3*</u>

Working free aim with default crosshair for spikes
Working free aim without crosshair for spores (doesn't need a cross hair it's not ranged)

Play away to your hearts content. Values can be adjusted but the box size works for me on 16:9.



<u>*Updated to Version 2*</u>
Current Status:
Free Aim for Lerk Spikes and Lerk Spores
Spores have no crosshairs
Spikes crosshair does not follow the free aim and stays centered in the screen.

Here I present Lerk Free Aim:

V1:


<center><object width="450" height="356"><param name="movie" value="http://www.youtube.com/v/AYIDd82fjZ8"></param><embed src="http://www.youtube.com/v/AYIDd82fjZ8" type="application/x-shockwave-flash" width="450" height="356"></embed></object></center>

The only issue so far is the crosshair doesn't move with the aim.

Works well and is a definite fun feature for the lerk. May need to expand the freeaim boundary. :)

Download Here:

<a href="http://www.duplexgaming.co.uk/downloads/mods/73/lerk_free_aim/" target="_blank">http://www.duplexgaming.co.uk/downloads/mo.../lerk_free_aim/</a>

Comments and suggestions, and help with getting the cursor moving all appreciated :

Comments

  • twilitebluetwiliteblue bug stalker Join Date: 2003-02-04 Member: 13116Members, NS2 Playtester, Squad Five Blue
    Nice job! I imagine it would be handy once the crosshair is working.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    Version 2 now up for download.

    I have added free aim to spores.

    I am unable to fix crosshair movement issue at the moment, so for spores I have removed the crosshair, as it's not a ranged attack, there is no need for it, and the view model movement clearly shows what direction your spores are going.

    Any help with why the crosshair is not moving is greatly appreciated :)
  • HarimauHarimau Join Date: 2007-12-24 Member: 63250Members
    edited February 2012
    How did Agiel get the crosshair moving?

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Script.Load("../ns2/lua/GUICrosshair.lua")

    // Update crosshair position

    if GUICrosshair.BaseUpdate == nil then
        GUICrosshair.BaseUpdate = GUICrosshair.Update
    end
    function GUICrosshair:Update(deltaTime)

        self:BaseUpdate(deltaTime)
        
        // FREEAIM:
        self.crosshairs:SetPosition(Vector(
            -GUICrosshair.kCrosshairSize / 2 + PlayerUI_GetCrosshairOffsetX(),
            -GUICrosshair.kCrosshairSize / 2 + PlayerUI_GetCrosshairOffsetY(),
            0))

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

    Comparing to your code:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function GUICrosshair:Update(deltaTime)

        PROFILE("GUICrosshair:Update")

        

        // Update crosshair image.
        local xCoord = PlayerUI_GetCrosshairX()
        local yCoord = PlayerUI_GetCrosshairY()
        self.crosshairs:SetIsVisible(true)
        self.crosshairs:SetColor(GUICrosshair.kInvisibleColor)
        if PlayerUI_GetCrosshairWidth() == 0 then
            self.crosshairs:SetColor(GUICrosshair.kInvisibleColor)
        elseif xCoord and yCoord then
            self.crosshairs:SetColor(GUICrosshair.kVisibleColor)
            self.crosshairs:SetTexturePixelCoordinates(xCoord, yCoord,
                                                       xCoord + PlayerUI_GetCrosshairWidth(), yCoord + PlayerUI_GetCrosshairHeight())
        end
          
        // FREEAIM:
        self.crosshairs:SetPosition(Vector(
            -GUICrosshair.kCrosshairSize / 2 + PlayerUI_GetCrosshairOffsetX(),
            -GUICrosshair.kCrosshairSize / 2 + PlayerUI_GetCrosshairOffsetY(),
            0))
        
        // Update crosshair text.
    ...    
        // Update give damage indicator.
    ...    
    end<!--c2--></div><!--ec2-->

    At the very least, these lines are missing:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if GUICrosshair.BaseUpdate == nil then
        GUICrosshair.BaseUpdate = GUICrosshair.Update
    end
    ...

        self:BaseUpdate(deltaTime)<!--c2--></div><!--ec2-->
    but... they don't seem to do much?

    Ehh... gotta look at " PlayerUI_GetCrosshairOffsetX() " these as well I guess. Hmm, but you've got that too.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    Agiels code is a sub class of Player_Client.lua

    He is calling this function:

    function GUICrosshair:Update(deltaTime)

    He is making his function self:BaseUpdate() a sub class of GUICrosshair:Update. In my code I added it directly to the GUICrosshair:Update code, thus eliminating the need for a separate sublclassed file.

    Again, I added both of those function to the main file, rather than extending the class into a sub file.
  • HadesDKHadesDK Join Date: 2008-07-31 Member: 64739Members
  • AgielAgiel Join Date: 2006-11-14 Member: 58605Members, Constellation, NS2 Playtester, Subnautica Playtester
    edited February 2012
    You need to update <i>Player:UpdateCrossHairText()</i> in Player_Client.lua since the new version does some stuff with the crosshair color. Just grab the new version and add
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// FREEAIM: Add offsets if weapon uses free aim.
    local weapon = self:GetActiveWeapon()
    if(weapon ~= nil and weapon.kUsesFreeAim) then
        viewAngles.yaw = viewAngles.yaw + self.freeAimYawOffset
        viewAngles.pitch = viewAngles.pitch + self.freeAimPitchOffset
    end<!--c2--></div><!--ec2-->after <i>local viewAngles = self:GetViewAngles()</i>

    The new fov calculations also mess up the crosshair position in 5:4 resolutions since the effective fov there is more like 70 instead of 90, but I guess that'll be fixed in the next build. Actually, I'm not sure if the lerk uses fov 90. You might need to do something like
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local angleScale = 90 / player:GetFov()
    return math.sin(-player.freeAimYawOffset*angleScale) * Client.GetScreenWidth() / 2<!--c2--></div><!--ec2-->when the crosshair offsets are calculated.

    I also realized we have a problem with gimbal lock when looking far up or down. Don't have an easy fix for that yet.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited February 2012
    I've already done that code change (player_client), it was required to get the mod working with 195. :)

    This isn't a fov issue, the view model works, the fire angles of the spikes and the spores is correct, it's just the crosshair stays rooted to the centre of the screen.

    It's almost like it is not picking up on the freeaim code in GUICrosshair. Either that or the alien crosshair is actually a full screen transparency with just the icon in the middle :P
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited February 2012
    For those people who worry about how free aim affects movement ability, I made a short video of lerk flight with free aim.

    The current issue I have with not making the cursor follow the free aim is a perfect opportunity to explain how this mod does not affect movement.

    Currently the crosshair is fixed in the centre of the screen as normal, but the free aim is working on the view model, and the spikes, as you can clearly see.

    What you can also clearly see is that whenever I move the mouse, although there is accelerated movement from the weapons, the cursor in the centre of the screen moves exactly as you expect.

    In this video you see the lerk flying, firing off target because of the free aim, but the crosshair in the centre of the screen is movement direction as controlled by the mouse. Flying issues are caused by the 15fps rather than free aim :)

    <center><object width="450" height="356"><param name="movie" value="http://www.youtube.com/v/FWxC9z96nIw"></param><embed src="http://www.youtube.com/v/FWxC9z96nIw" type="application/x-shockwave-flash" width="450" height="356"></embed></object></center>

    So this lead me to an idea, how about implementing a 'dual' crosshair, at least initially while people learn the nuances of lerk free aim.

    How about keeping a tiny centre crosshair, like the dot i'm using, always in the centre of the screen, to help with understanding flight direction (although really it's not very confusing), and add a secondary outer crosshair that moves with the free aim of the spikes?

    Let me know thoughts on that :)


    -----EDIT------
    As a test, deleted the code from GUICrosshair, and just used the vanilla NS2 file with your extension, but still the same issue, so I can rule out the GUICrosshair file. There are no code errors, the code is solid, but the effect we desire is not forthcoming :P
  • HarimauHarimau Join Date: 2007-12-24 Member: 63250Members
    edited February 2012
    I like the dual crosshair idea. Ideally they would kinda... normally form one crosshair, rather than be two instances of the same crosshair. Here's an example of what I mean (not a suggestion):
    <img src="http://i.imgur.com/HOs8O.png" border="0" class="linked-image" />
    Above: rotationally stationary
    Below: rotationally in motion
    Blue is the movement crosshair, and is stationary with the view.
    Red is the aim crosshair, and is independent of the view.
  • AgielAgiel Join Date: 2006-11-14 Member: 58605Members, Constellation, NS2 Playtester, Subnautica Playtester
    Have you tried setting <i>kFreeAimOn = true</i> ?
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited February 2012
    HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA

    I forgot that previously, when testing your mod, I was implementing a console command to enable freeaim, lol, somehow i've used part of that code, hahaha. Right, kFreeAimOn = true kind of works :)

    I have free aim cursor on vertical up and down movements, but not horizontal. :P

    Gonna check it out now :) Adding your FOV code to test.

    Still not working on the horizontal.

    Here is the code for the crosshair offsets:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// Get crosshair X position
    function PlayerUI_GetCrosshairOffsetX()
        local player = Client.GetLocalPlayer()

        if(player and not player:GetIsThirdPerson()) and KFreeAimOn == true then  
          
            local weapon = player:GetActiveWeapon()
            if(weapon ~= nil and weapon.kUsesFreeAim) then
            
                // Don't ask me why this works. afaik sin(45) isn't 1
                local angleScale = 90 / player:GetFov()
                return math.sin(-player.freeAimYawOffset*angleScale) * Client.GetScreenWidth() / 2
                
            end
            
        end
            
        return 0
    end

    // Get crosshair Y position
    function PlayerUI_GetCrosshairOffsetY()
    local player = Client.GetLocalPlayer()

        if(player and not player:GetIsThirdPerson()) and kFreeAimOn == true then  
          
            local weapon = player:GetActiveWeapon()
            if(weapon ~= nil and weapon.kUsesFreeAim) then
            
                return math.sin(player.freeAimPitchOffset) * Client.GetScreenWidth() / 2
            
            end
            
        end
            
        return 0
    end<!--c2--></div><!--ec2-->

    OffsetY is working OffsetX is not. There are no code errors. The effect is the same if OffsetX is:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function PlayerUI_GetCrosshairOffsetX()
        local player = Client.GetLocalPlayer()

        if(player and not player:GetIsThirdPerson()) and KFreeAimOn == true then  
          
            local weapon = player:GetActiveWeapon()
            if(weapon ~= nil and weapon.kUsesFreeAim) then
            
                // Don't ask me why this works. afaik sin(45) isn't 1
                return math.sin(-player.freeAimYawOffset) * Client.GetScreenWidth() / 2
                
            end
            
        end
            
        return 0
    end<!--c2--></div><!--ec2-->
  • AgielAgiel Join Date: 2006-11-14 Member: 58605Members, Constellation, NS2 Playtester, Subnautica Playtester
    <i>KFreeAimOn</i> in PlayerUI_GetCrosshairOffsetX() should be <i>kFreeAimOn</i>
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    well spottted :)

    I was looking for spelling errors but just didn't catch it ::)
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited February 2012
    <u>*Updated to Version 3*</u>

    Working free aim with default crosshair for spikes
    Working free aim without crosshair for spores (doesn't need a cross hair it's not ranged)

    Play away to your hearts content. Values can be adjusted but the box size works for me on 16:9.

    As an FYI Agiel, I left your code:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local angleScale = 90 / player:GetFov()
    return math.sin(-player.freeAimYawOffset*angleScale) * Client.GetScreenWidth() / 2<!--c2--></div><!--ec2-->

    in the release code, but I just tested with the original code and that works too on my 16:9 setup.

    I believe Gimbal lock only affects marines as they are stuck on a plane. With the lerk I look straight up, go straight up, and a simple left or right rolls me to then I turn and swoop down.

    The lerk flight is completely free and natural, just takes a little bit of play time to get used to the bounding box, then lerk flight is easy as normal, but with a better aiming ability.

    This is really brilliant, and I'd like to thank you Agiel for the original code and I'd like to thank Mushokees for the original idea of adapting it to the lerk. I am really enjoying this. It is in my TDM mod, but I'm not going to update the release file just yet. Want to look a bit more at the gorge powerslide, and see if I can knock together a quick map for the mod :)
  • AgielAgiel Join Date: 2006-11-14 Member: 58605Members, Constellation, NS2 Playtester, Subnautica Playtester
    edited February 2012
    <!--quoteo(post=1903826:date=Feb 16 2012, 08:29 PM:name=Soul_Rider)--><div class='quotetop'>QUOTE (Soul_Rider @ Feb 16 2012, 08:29 PM) <a href="index.php?act=findpost&pid=1903826"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->As an FYI Agiel, I left your code:
    ...
    in the release code, but I just tested with the original code and that works too on my 16:9 setup.

    I believe Gimbal lock only affects marines as they are stuck on a plane. With the lerk I look straight up, go straight up, and a simple left or right rolls me to then I turn and swoop down.<!--QuoteEnd--></div><!--QuoteEEnd-->
    I guess the lerk does use 90 degrees fov then. The crosshair wont be aligned in 5:4 though since the fov there would be 70 degrees due to a bug in the current build as I mentioned earlier.

    The problem with gimbal lock is with the aim vector. Try looking straight up and then a bit to the side. The view model and crosshair will look right but the aim vector will still be pointing straight up since the yaw component adds roll instead of yaw. What we need to do is somehow apply the pitch and yaw offsets while treating the view vector as the z axis. I'll look into it when I get the time (which I don't have atm since I'm going to Japan on Monday and it'll be a while until I get all set up over there ;).
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    This is getting a bit close to the issue we had with the skulk view rotation when wall walking, and we never got a fix for that :P
  • HarimauHarimau Join Date: 2007-12-24 Member: 63250Members
    <!--quoteo(post=1903888:date=Feb 17 2012, 05:27 AM:name=Soul_Rider)--><div class='quotetop'>QUOTE (Soul_Rider @ Feb 17 2012, 05:27 AM) <a href="index.php?act=findpost&pid=1903888"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->This is getting a bit close to the issue we had with the skulk view rotation when wall walking, and we never got a fix for that :P<!--QuoteEnd--></div><!--QuoteEEnd-->
    Abandon ship.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited February 2012
    <!--quoteo(post=1903841:date=Feb 16 2012, 08:07 PM:name=Agiel)--><div class='quotetop'>QUOTE (Agiel @ Feb 16 2012, 08:07 PM) <a href="index.php?act=findpost&pid=1903841"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Try looking straight up and then a bit to the side. The view model and crosshair will look right but the aim vector will still be pointing straight up since the yaw component adds roll instead of yaw. What we need to do is somehow apply the pitch and yaw offsets while treating the view vector as the z axis. I'll look into it when I get the time (which I don't have atm since I'm going to Japan on Monday and it'll be a while until I get all set up over there ;).<!--QuoteEnd--></div><!--QuoteEEnd-->

    Ok I understand this is a potential problem, however, I'd like to make a comparison to another flying object, a plane.

    Now I know the difference, but when flying a plane, you roll to bank and yaw to turn slightly. When flying straight upwards, or downwards, if you roll to turn you just spin in one spot always facing straight up.

    I know the actual ingame set up is mouse does Yaw and Pitch, but because we use 'Mouse Yaw' to turn (bank) right in flight, turning right when facing straight up should make the Lerk roll, just like a an aeroplane.

    All we need to do is clamp free aim at 0 and 180 degrees, and this should be fine.

    I know technically it's not correct, but because of the way the Lerk flight is controlled, spinning when aiming left or right while straight up or down is the correct flight simulated response.


    <!--quoteo(post=1904039:date=Feb 17 2012, 04:03 AM:name=Harimau)--><div class='quotetop'>QUOTE (Harimau @ Feb 17 2012, 04:03 AM) <a href="index.php?act=findpost&pid=1904039"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Abandon ship.<!--QuoteEnd--></div><!--QuoteEEnd-->

    I'm trying to save Agiel a lot of heartbreak. He doesn't want to try that, unless he can solve it, in which case we will be able to get the skulk view rotation working with the same code :)
Sign In or Register to comment.