Forum rules - please read before posting.

AC for side-scroller control and adventure game mechanics

Hello everybody,

First of all, thank you for your great plugin! Seems like making adventure games in Unity wasn't so easy before.
Alas, I'd like to make not a classic 'point-n-click' game. And the plugin doesn't allow to do this just out of the box.

I'd like to make 2D side scroller with adventure mechanics. When I can interact with objects by walking closer to them and pressing a key.

I can see many similar questions about such format on the forum here.
I found a partial decision of my issues. But in complex the making of a prototype is still hard.

And the first questing is... Could you please make a tutorial - video or at least text - how to make a side-scroller control with object interactions and other adventure game features?
Cause everything works wrong on my side in details. A step by step manual could really help.

If it's not possible, please take a look at my panels screenshots and help me please to make sense of some troubles.

1) For the prototyping I use Brain2d prefab. I made a platform as a scene, chose direct moving method and keyboard control,
deactivated moving for up and down via action list. Brain moves just along X-axe. But when I press left and right very quickly, Brain makes turning back and forth in place and moves in Z-axe (deep in depth or, vice versa, closer to camera).
That's because there is a small movement along Z in turning animation. But how can I switch it off?

2) I control Brain by keyboard, and set Interaction A and B on keys. It's all fine, except one moment.
The mouse cursor is switched off. But the engine scans the cursor coordinates. If I press a key for Interaction A, Brain turns to that side, and right after I press left or right key, he moves to the cursor coordinates himself.
Why does it happen?

3) Player-vicinity detection. I made all just like in Manual. Hotspot detector doesn't work right. I guess there is a conflict of rigid body and collider components.
The root or base object of my character - Brain2D prefab - contains them both.
But if I'm right, the hotspot detector child should have circle collider too, (and maybe even rigidbody). So I did this way. But now I can see two warnings in the hotspot detector component:
"A Rigidbody component must be placed on this object"
"A Collider component must be placed on this object".

In the result hotspot detector doesn't affect the items. And moreover, it doesn't turn with the character, staying always on one side.

4) Is it possible to make the box collider instead of circle one? Sometimes the character falls over slowly - it's the circle collider spins on the flat platform.

5) How to make the jump? I can see in different panels mentioning (parameteres) of this feature. But how to switch it on?

Thank you for your time and attention! And sorry if I ask silly questions. I will appreciate your answers very much.

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes

Comments

  • edited December 2020

    Welcome to the community, @Gilvat.

    The main issue here is that your game is set to be in 3D - not 2D. This means that AC expects all your objects (including physics components etc) to be in 3D - hence the Hotspot detector asking for a Rigidbody, and not a Rigidbody 2D.

    In your Settings Manager, change your Camera perspective field to 2D.

    It would be best to also start over with the scene. When AC's Scene Manager is used to create a new scene, it will set things up differently based on the above setting at the time. At the very least, you should remove your scene's MainCamera and Default PlayerStart, and then re-organise your scene objects at the top of the Scene Manager.

    The Hotspot Detector requires a Rigidbody (Rigidbody 2D for a 2D game) to be present on either the detector, or the root. Since Brain already has one on his base, you don't need to add a new one - a Circle Collider 2D on the Hotspot Detector should be enough.

    For instant turning, give Brain's Turn speed a value of -1. A negative value will allow for turning instantly.

    Let's see how many of the above issue these steps solve. It may be that there's a bit more to tweak - but that should help with the biggest issues. Have a look, and let me know how things go!

  • Hello @ChrisIceBox ,

    thank you for your answer!

    Indeed, everything works much better now, when I use 2D set.
    Nevertheless, is it possible somehow to work with sprites in 3D space - with real parallax of layers, not imitated by "Parallax 2D" component?

    Alas, I still have a problem with the one side hotspot detector. It's not turning with the character body. (the screenshot below).
    Is it possible to fix this without going in the scripting?

    Yes

    The next questions is quite complicated...

    I'd like to have the control system, when I choose the needed type of interaction, just cycling them by a key button.
    And then use the selected one on a hotspot by another key. And accompany the interaction cycling by a suitable character animation.
    In this logic I don't need the inventory menu, because each object appears in the character hand.

    At this moment I set the cycling of standard interactions like "use", "talk" and "look" for InteractionB button, and using the selected one by InteractionA button.
    Instead of needed animations I just have the text lables on the screen. So, my questions are...

    1) I have a bug that I can't beat. Before an interaction with a hotspot, the text lable appears at the head of the screen. But after the interaction it appears in the item lable place.
    What did I do wrong in my panels?

    Yes

    Yes

    Yes

    2) Please advise how can I make the desirable control system with choosing the interactions and following animations?
    Is it possible to create such system just by setting the AC editor?

    Thank you for your time and answers. Looking forward to hearing from you.

    And sending you my festive season greetings!

    Yes
    Yes
    Yes
    Yes
    Yes

  • edited December 2020

    is it possible somehow to work with sprites in 3D space - with real parallax of layers, not imitated by "Parallax 2D" component?

    AC's standard camera type for 2D games - GameCamera 2D - moves without changing the perspective, even if using Perspective projection. This is normally what you'd want in a 2D game, so that an object's Z position has no bearing on its visual position.

    However, you can choose to make use of the standard camera type for 2D games - GameCamera - instead. It won't appear in the Scene Manager, as that'll only list 2D prefabs, but you can drag it into your scene manually from /Assets/AdventureCreator/Prefabs/Camera. You can then assign that as your scene's default. When that moves sideways, objects in the distance will move across the screen more slowly.

    I still have a problem with the one side hotspot detector. It's not turning with the character body. Is it possible to fix this without going in the scripting?

    If the Hotspot Detector is on a child object of wherever your character's Animator is, you can control its position within the character's animation files. So for example, Idle_R and Walk_R could set its local position to be +0.5, while Idle_L and Walk_L could set it to -0.5.

    A script would just as easily get the job done, though. Here's a script that, when attached to the Player, should do it:

    using UnityEngine;
    using AC;
    
    public class SetDetectorPosition : MonoBehaviour
    {
    
        public float horizontalShift = 0.5f;
        private Player player;
        private Transform detectorTransform;
    
        void Awake ()
        {
            player = GetComponent <Player>();
            detectorTransform = player.hotspotDetector.transform;
        }
    
        void Update ()
        {
            if (player.GetSpriteDirectionInt () == 2)
            {
                // Facing right
                detectorTransform.localPosition = new Vector3 (horizontalShift, detectorTransform.localPosition.y, detectorTransform.localPosition.z);
            }
            else
            {
                detectorTransform.localPosition = new Vector3 (-horizontalShift, detectorTransform.localPosition.y, detectorTransform.localPosition.z);
            }
        }
    
    }
    

    In either case, be sure to uncheck Turn root object in 3D? in your Player Inspector so that his rotation never changes.

    Before an interaction with a hotspot, the text lable appears at the head of the screen. But after the interaction it appears in the item lable place.

    I can't recreate such behaviour. What version of AC are you using?

    There must be a reason for it startingat the top-left. Is that where the mouse cursor is? Or perhaps an inventory item? Try locking or deleting your Inventory menu if you have no need for it.

    Are you looking to only see/change the interaction type when a Hotspot is in the vicinity? Try going back to "Choose Hotspot Then Interaction" mode as you did before if so - I notice you switched to Choose Interaction Then Hotspot since.

    Please advise how can I make the desirable control system with choosing the interactions and following animations?

    Generally speaking, control systems come in two parts: how they control, and how they look. You'll have to elaborate on what exactly it is you're after in both of these senses. I'd suggest focusing on just the way it controls first, which hopefully should just be a case of setting the right fields in your Managers.

    Adding things like animation would come second. You're looking to animate the character? In what way, exactly? You'd need to use some custom scripting to animate the character based on the current "cursor", but that shouldn't be too troublesome and I can assist with that. But the more clear you can lay out your intent, the better I can do so.

  • Thank you for your answer!

    I need some time to implement and experiment with your recommendations.

    Speaking about the control system, I’ll try to explain it clearer.

    One of the basic mechanics of the adventure games is finding and gathering items, which allow to make new interactions (once or many times) - usually by choosing the suitable item in the inventory. In my vision the logic is the same, just without having the inventory menu.

    So, first the character has the only interaction - «Use». Then he can find a crowbar for example and has the new interaction - «Brake». Later he will find a screwdriver maybe, gather it by «Use» and will have the third interaction - «Unscrew».

    Now, in this case I have three different interactions. I can cycle them by InteractionB button, just stop on the needed one and apply on a hotspot by InteractionA button.

    Because the game doesn’t have the inventory menu, as a gamer I need to see the chosen interaction on my character. So, the suitable item (crowbar, screwdriver, etc.) appears in his hand. That’s why I guess «Choose Interaction Then Hotspot» mode is better for this idea.

    And concerning the part of control system «how they look» - when I cycle the interactions I need to see how my character gets in his bag and takes another item in his hand.

    I believe there should be an exact example of a game with such mechanic, but I couldn’t recall it. So, I decided to describe it in detail just in case.

    I hope I’ve managed to explain the idea well. Thank you for your help!

  • Thanks for the details.

    For each Interaction icon you can define in the Cursor Manager has a Leave out of Cursor cycle? option, which you can use to prevent it from becoming selectable through regular input. From the sound of it, it seems like you want to be able to start off with just one icon in the cycle, and include more as the Player progresses.

    These options aren't something that normally get changed at runtime, but it's easy to do so through custom scripting. Any Manager field value can be modified at runtime - just right-click to get an API reference to its variable, which you can insert into your own script.

    Here's a custom Action script that uses that technique to change that toggle box for a given Icon ID:

    using UnityEngine;
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionToggleIcon : Action
        {
    
            public int iconID;
            public bool enable;
    
            public ActionToggleIcon ()
            {
                this.isDisplayed = true;
                category = ActionCategory.Custom;
                title = "Toggle icon";
            }
    
            public override float Run ()
            {
                KickStarter.cursorManager.GetCursorIconFromID (iconID).dontCycle = !enable;
                if (!enable && KickStarter.playerCursor.GetSelectedCursorID () == iconID)
                {
                    // Disabling the current icon
                    KickStarter.playerCursor.ResetSelectedCursor ();
                }
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                iconID = UnityEditor.EditorGUILayout.IntField ("Cursor icon ID:", iconID);
                enable = UnityEditor.EditorGUILayout.Toggle ("Enable?", enable);
    
                AfterRunningOption ();
            }
    
            #endif
    
        }
    
    }
    

    Paste that into a new C# file in a new directory in your project, then point to it in the "Custom Actions" section of the Actions Manager. It should then appear as a new Action named Custom: Toggle icon in your ActionLists. Just supply the ID value of the icon you want to affect, and you can have it turn on or off as part of your game logic, e.g. in an Interaction ActionList.

    Be aware, though, that such changes won't be recorded in save-game files, but a similarly simple script can be used to handle that - but let's get the basic mechanics down first.

    As for animating the character: how this'll work exactly will depend on how you want to trigger such animation in their Animator. On a very basic level, you can create an Integer parameter in your Animator Controller that matches itself to the ID of the Player's currently-selected icon. To sync the two values together, you can make use of AC's OnChangeCursorMode event hook, which will trigger every time the Player changes cursor mode through right-clicking.

    Event hooks are a way of extending AC when common tasks are performed. Here's another sample script that updates a the Player Animator's "IconID" integer parameter when the Player changes cursor mode:

    using UnityEngine;
    using AC;
    
    public class AnimateIconID : MonoBehaviour
    {
    
        void OnEnable () { EventManager.OnChangeCursorMode += OnChangeCursorMode; }
        void OnDisable () { EventManager.OnChangeCursorMode -= OnChangeCursorMode; }
    
        void OnChangeCursorMode (int iconID)
        {
            KickStarter.player.GetAnimator ().SetInteger ("IconID", iconID);
        }
    
    }
    

    Just attach that to your Player as a C# script named AnimateIconID, once you've defined an Integer parameter named "IconID" in their Animator Controller.

  • Thank you very much for all your help!

    I know, many of my questions and troubles are quite dumb. I'm really sorry for that.
    I can't find the correct way to transit to the alternative set of animation, when Brain takes and carries the lunch bag.

    Brain strobes between first frames of the sequences. I could make the screenshots of my settings.
    But in fact I've been experimenting many different ways. Alas, the result is the same.

    Could you try to make the correct settings in your project? I uploaded here the link to the archive with my alternative animation sequences.
    https://drive.google.com/file/d/1Ja9OXPN2Zz4f4HHsoMOwUg-moe90L3NN/view?usp=sharing

    Thank you for your time. And, sending you my greetings on Christmas!

  • edited December 2020

    Having the sprites alone isn't enough - the exact method would depend on how your character is set up, both in terms of the prefab fields and the Animator Controller.

    The main factor that affects the method is your chosen "Animation engine". Are you using Sprites Unity or Sprites Unity Complex?

    If you're using Sprites Unity Complex, then all character animations are played based on parameter values and transitions that you manually define - giving you exact control over what gets played and when.

    The AnimateIconID script above will control an Integer parameter named "IconID", which you can factor into your Animator by having it cause your regular Idle/Walk etc animations to be replaced by an alternative set of animations.

    If you're using Sprites Unity, though, then character animations are played by AC automatically, using a strict naming convention (i.e. BrainWalk_R, BrainIdle_L etc).

    To change animation with this mode, you can't use a parameter value - because AC will continue to play animations automatically, overriding the effects of any transitions you set up. I suspect this is what's causing your "strobing" issue.

    In this mode, standard animations (idle, walk, etc) are changed instead by changing the field names you've set in your Player Inspector. So for example, the "Idle name" field would be changed from e.g. BrainIdle to BrainIdle_Bag.

    Here's an alternative to the AnimateIconID script that instead uses that method:

    using UnityEngine;
    using AC;
    
    public class AnimateIconID : MonoBehaviour
    {
    
        void OnEnable () { EventManager.OnChangeCursorMode += OnChangeCursorMode; }
        void OnDisable () { EventManager.OnChangeCursorMode -= OnChangeCursorMode; }
    
        void OnChangeCursorMode (int iconID)
        {
            if (iconID == 0)
            {
                // Bag
                KickStarter.player.idleAnimSprite = "BrainIdle_Bag";
                KickStarter.player.walkAnimSprite = "BrainWalk_Bag";
            }
            else if (iconID == -1)
            {
            // Default
                KickStarter.player.idleAnimSprite = "BrainIdle";
                KickStarter.player.walkAnimSprite = "BrainWalk";
            }
        }
    
    }
    

    As you can see, it's a little more script-side because you have to change the names of all your animations (update the script to match your own animation names if they're different).

    If you need more assistance, please share more details in terms of how exactly your character is set up, and what changes you've added so far.

  • Thank you very much for all the explanation!

    Can you please check your new AnimateIconID script. Seems like it plays both animations (Idles and Walks) just in one time.
    Cause in my case character walks on the spot with a bag. And when I press a direction button, he walks without a bag.

  • Quite right, sorry about that.

    You'll still need to tweak the script to suit your needs, but I've corrected the idle/walk animations above.

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.