Forum rules - please read before posting.

Checking if the player is crouching

Hello everyone! So I've been looking for a way to check when the player is crouching, I'm using the first person controller that its available at the AC website and has the FPcrouch script.

I've been looking in the documentation, the manual and this forum but I can't seem to find an answer. I tried putting a Global variable inside the FPcrouch script, and while it compiled find, it didn't worked. Maybe there's an easy way to check but I haven't been able to find it. Thanks in advance.

Comments

  • edited March 2023

    Welcome to the community, @LegForDays.

    Through script, you can determine this by reading the FPCrouch script's IsCrouching property, i.e.:

    bool isCrouching = GetComponent<AC.FPCrouch> ().IsCrouching;
    

    You can use this in a custom script (SetCrouchVariable) attached to the same object to sync it with a Global Boolean Variable that you can then read within ActionLists:

    using UnityEngine;
    using AC;
    
    public class SetCrouchVariable : MonoBehaviour
    {
    
        public string globalVariableName;
    
        void Update ()
        {
            bool isCrouching = GetComponent<AC.FPCrouch> ().IsCrouching;
            GlobalVariables.GetVariable (globalVariableName).BooleanValue = isCrouching;
        }
    
    }
    
  • Thanks a lot! It worked with no issues.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.