Forum rules - please read before posting.

Walk to the point - OWN ACTION

Hey!

I am creating an adventure game, with a platformer game controls. I use CUSTOM MOTION CONTROLLER, and I do not use any ANIMATION ENGINE (I am using the standard unity animator system). Now I want the player to move to a marker, whenever I click the hotspot, detected by player vicinity. I do not want to use a "Character : Move to point", because of these reasons

  • I do not use any animation engine, so the player WALK animation is not playing
  • Whenever I change the controls to Automatic, the Gravity Scale changes to 1
  • When I tried to do this, it had a lot of bugs

I would like to create my custom action, which will include animation playing, player flipping (whether the marker is on the right, or on the left), changing the x position of the player until he reaches the marker (an empty object). I tried to search through your tutorials on how to make an Action, but you covered only the disposable action (like change one parameter), but this Action requires the looping of it until it reaches the point, which I didn't figure out on how to do it.

I would be delighted if you could just help me with this Action because I really need this feature to make my game work.
Thank you really much for your response!
WOLF FLARE

Comments

  • edited September 2019

    I do not use any animation engine, so the player WALK animation is not playing

    If you would like to the "Animation engine" field to change to "Automatic" whenever the Player moves along a path, you can do so by hooking into the OnCharacterSetPath / OnCharacterEndPath custom events:

    using UnityEngine;
    using AC;
    
    public class AutoSetPlayerAnimationEngine : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnCharacterSetPath += OnSetPath;
            EventManager.OnCharacterEndPath += OnEndPath;
        }
    
        private void OnDisable ()
        {
            EventManager.OnCharacterSetPath -= OnSetPath;
            EventManager.OnCharacterEndPath -= OnEndPath;
        }
    
        private void OnSetPath (Char character, Paths path)
        {
            if (character is Player)
            {
                character.SetAnimEngine (AnimationEngine.SpritesUnity);
            }
        }
    
        private void OnEndPath (Char character, Paths path)
        {
            if (character is Player)
            {
                character.SetAnimEngine (AnimationEngine.Custom, "MyCustomEngine");
            }
        }
    
    }
    

    Whenever I change the controls to Automatic, the Gravity Scale changes to 1

    In the latest AC release, this is now set to whatever the Rigidbody 2D's Gravity Scale is originally set to.

    this Action requires the looping of it until it reaches the point, which I didn't figure out on how to do it.

    See the comments inside the provided ActionTemplate script. To have an Action last more than a frame, your Run function needs to return the duration before it is next run.

    If this is non-zero, the Run function will continue to be invoked until isRunning is False, and you return zero.

    To have an Action wait just one frame repeatedly, so that the Run can check each frame if something has been completed (like an Update) function, return "defaultPauseTime". This is a typical pattern for that kind of behaviour:

    override public float Run ()
    {
        if (!isRunning)
        {
            isRunning = true;
    
            // Start doing something
    
            return defaultPauseTime;
        }
        else
        {
            // Check if the thing has completed
            // If it has not yet finished:
            return defaultPauseTime;
        }
    
        // The thing has finished
        isRunning = false;
        return 0f;
    }
    
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.