Call Aim Item Ability programmatically

Thiago

New member
Hi, people,

I try to find in forum but maybe I´m not using the right words to search.

So what I need is stay aiming automatically when enter some places, like inside houses, for instance.

How can I do that?

For camera zoom, I create a method in CameraHandler like below. The logic its simple, when "collision stay" set isFixedZoom = true. But its not good because I fixed "Fire2" inside the code. But works ;)

Code:
public void FixedZoom(bool isFixedZoom){
            if(isFixedZoom) {
                m_ZoomInputName = "";     
                m_ContinuousZoom = false;
            } else {
                m_ZoomInputName = "Fire2";     
                m_ContinuousZoom = true;
            }
        }

Thx a lot!

Thiago
 
Last edited:
You can use TryStartAbility on ItemAbilities. This page has an example with the jump ability, but it's the same concept with item abilities.

 
You can use TryStartAbility on ItemAbilities. This page has an example with the jump ability, but it's the same concept with item abilities.


Hi, Justin

Thx a lot!!! Works fine!!

C#:
public void fixedAim(bool isFixedAim){
           var aimAbility = this.GetAbility<Aim>();
           if(isFixedAim){
               this.TryStartAbility(aimAbility);
               return;
           }
           this.TryStartAbility(aimAbility);
        }

https://photos.app.goo.gl/bwcYkqihMHpi3uHQ9
 
I'm currently trying activate/deactivate the Aim ability by code and need some help, don't know what I'm doing wrong.

This is the code I'm using. I have the Start/Stop types as Manual. Am I missing something?

C#:
public class AimIK : MonoBehaviour
{
    private UltimateCharacterLocomotion ucl;
    private Aim aim;

    private void Awake()
    {
        ucl = gameObject.GetComponent<UltimateCharacterLocomotion>();
        aim = ucl.GetAbility<Aim>();
    }

    public void StartAim()
    {
        ucl.TryStartAbility(aim, true);
    }

    public void StopAim()
    {
        ucl.TryStopAbility(aim, true);

    }
}
 
That looks correct. If you place a breakpoint in TryStartAbility where does it fail?
 
I haven't worked with breakpoints before so I'm not completely sure I did this right, but every break point I set was reached.
I am using UFPS 2.1.10 if that makes a difference.
 
This is a good guide for breakpoints:


You'll want to step into the functions to see why the aim ability isn't starting. If you are in a first person view the aim ability automatically starts by default because of the Activate In First Person field. Maybe it is failing because it is already started?
 
Cool thank you!

I forgot about that, the issue is something else then, the item ability is always active but it is not activating the Aim states on my items when using the above code. If I change it to Button down/Button up it activates the states correctly.
 
Top