Forum rules - please read before posting.

Event for "SetlookDirection"

Hi, it would be great if there was something like an "OnSetLookDirection" event that is fired whenever "SetLookDirection" of the Char script is called. (Similar to OnPathSet).

Currently the way we build our custom character controller is that once the character reaches the end of the path, we get use GetTargetRotation (), but this seems to be too early in time.

To make it a little clearer: We are using the ActionCharPathfind set to wait until finish and rotate after. In this case, when call GetTargetRotation () after the end of the path is reached, the action hasn't updated the Target Rotation yet. (We tried to exactly understand what was happening by invoking GetTargetRotation () after a couple of seconds and it works then.)

Having a "OnSetLookDirection" event would provide an easy and efficient way to know whether and when the look direction of the Char has to be changed by other scripts. (Ideally with the char in addition to the direction and isInstant parameters)

Thank you.

Comments

  • Sounds reasonable - I'll give it some thought.

  • I've done some research, and the main issue for me is that SetLookDirection can actually be called every frame depending on how the character is being moved.

    I'm not sure there'd be much difference between hooking into such an event vs reading GetTargetRotation, as a result. Have you tried reading GetAngleDifference instead?

  • Hi Chris,

    Well the main difference still would be that we can exactly know „when“ AC Updates the Look Direction. In our case, when we use the pathfinding, its updated once when the character reaches the point we define. Even if it was called every frame for certain cases, it would help us to know ACs „intentions“.
    The problem with using GetAngleDifference and similar other ways is, that as you know its pretty much impossible to be „exactly accurate“ when it comes to navigation, its always just close enough, which is fine regarding the accuracy, but it makes it difficult to sync ac and other systems. For example:
    When does AC consider it has reached the desired lookdirection so we move to the next action? Setting the threshold too high for triggering a rotation can make small rottation changes hard to get for our custom controller.
    Another thing is that we are using motion matching, so we are able to reach the desired final rotation in exactly one step. If we set the look direction multiple times, we get a jittery turning animation, as the system tries to quickly blend between different angle animations.

    What worked great in our testing was for example modifying the charpathfind action and adding an event to it that gives us the final position and rotation (when wait until finish and copy marker position is checked). With this info right in the beginning, we can navigate to that exact point in a realistic way (for example if the point is slightly behind the character, he just moves a little step backward instead of turning moving and turning again).
    Of course this is a very special case and only works when we use the charpathfind action (but not when turning without moving).

    TLDR: It would be great to know when exactly AC switches to different stages of movement (movement, rotation) and updates the desired rotation, to sync it with other systems reliably and to avoid getting „old“ values.

    Hope this is understandable... its always hard to „talk“ about these thigns without showing :)
    And as always, thanks for your amazing work.

  • It's a difficult issue to visualise, but perhaps it's best to just try it out and see if it's the right way forward.

    In EventManager.cs, paste the following into the main body:

    public delegate void Delegate_SetLookDirection (AC.Char character, Vector3 direction, bool isInstant);
    public static Delegate_SetLookDirection OnSetLookDirection;
    
    public void Call_OnSetLookDirection (AC.Char character, Vector3 direction, bool isInstant)
    {
        if (OnSetLookDirection != null)
        {
            OnSetLookDirection (character, direction, isInstant);
        }
    }
    

    Then, in Char.cs, replace the SetLookDirection function with the following:

    public void SetLookDirection (Vector3 _direction, bool isInstant)
    {
        Vector3 oldLookDirection = lookDirection;
        lookDirection = new Vector3 (_direction.x, 0f, _direction.z);
    
        if (KickStarter.settingsManager.rotationsAffectedByVerticalReduction && SceneSettings.IsUnity2D () && KickStarter.settingsManager.movementMethod == MovementMethod.PointAndClick)
        {
            if (_direction != TransformForward)
            {
                // Modify 3D direction so that it appears more correct in 2D
                    lookDirection.z /= KickStarter.sceneSettings.GetVerticalReductionFactor ();
            }
        }
    
        if (isInstant)
        {
            Turn (isInstant);
        }
    
        if (oldLookDirection.normalized != lookDirection.normalized)
        {
            KickStarter.eventManager.Call_OnSetLookDirection (this, lookDirection, isInstant);
        }
    }
    

    That should provide you with such an event - does that suit your needs?

  • Hi Chris, thank you I just tested it, and I now understand what you mean with "it often triggers every frame", but it's still very useful and worked great, especially for my use case, where I only need that info at the end of a path, in which case it actually only triggers once.

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.