Forum rules - please read before posting.

[Mechanic] Trigger a variable when running (Double Clicking) possible?

Hello. 

First, let me explain what I'd like to achieve in order to give the proper context.
I've set up a "sanity/hp meter" in the game. And I'd like to make it so that when it is below (sanity) a certain value and the character runs (the player double clicks) to trigger a trip animation, (player movement stops, animation plays, etc.)

Is it possible to do this when the run action is triggered? Another example: the trip/fall action can be triggered by obstacles placed in the level (I'd add an on Enter trigger), but that would still require it to happen only when the character runs.

I know how to set it all up, but I don't know how to set it up to only happen when the user runs.

As usual, thank you in advance for your help.

Comments

  • Through scripting, you can check if the Player is running with:

    AC.KickStarter.player.isRunning
    

    If you want to make this check at the point the user double-clicks in the scene to run, you can hook into the OnPointAndClick custom event. This could be as simple as running an ActionList asset if its run parameter is true:

    using UnityEngine;
    using AC;
    
    public class PlayerRunListener : MonoBehaviour
    {
    
        public ActionListAsset actionListOnRun;
    
        void OnEnable () { EventManager.OnPointAndClick += OnPointAndClick; }
        void OnDisable () { EventManager.OnPointAndClick -= OnPointAndClick; }
    
        void OnPointAndClick (Vector3[] pointArray, bool run)
        {
            if (run)
            {
                actionListOnRun.Interact ();
            }
        }
    
    }
    
  • By "Custom Event" you're refering to the last option in the Action Type called "Custom"? Whenever I select it it defaults to "Action List". So, to reiterate. "OnStart", create a new "Action", select "Custom", Select "OnPointAndClick"? Sorry, not much of a programmer.

  • The Custom Event system is separate from Actions - see the tutorial I linked to above, as well as the Manual's "Custom events" chapter for details.

    Custom events can be make use of either through scripting (as above), or with the Events Editor.

    To use my example, create a new C# script named PlayerRunListener, and replace its code with the above.

    Then attach this script to an object in the scene. Assign its "Action List On Run" Inspector field to an ActionList asset file, which will then run whenever the user double-clicks to have the Player character run.

  • it worked! thank you so much for you help!

  • edited November 2023

    hi @ChrisIceBox . Hope you're having a wonderful day. I was wondering if you knew what this error is about. I updated today to the latest version of AC and this happened. The issue seems to be with PlayeRunListerner. here's a screenshot of everything. as always thank you so much for your help.

  • edited November 2023

    It's down to this section of the v1.79.0 changelog:

    • The OnPointAndClick custom event now uses the "ref" keyword for its pointArray parameter

    To fix, replace:

    void OnPointAndClick(Vector3[] pointArray, bool run)
    

    with:

    void OnPointAndClick(ref Vector3[] pointArray, bool run)
    
  • thank you so much. that did the trick. have a wonderful rest of the day.

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.