Forum rules - please read before posting.

2d character looking up and down (and spotting hotspots)

First time posting and I certainly apologise if I'm doing this wrong!
I'm using 2d worldspace with direct control and noticed you can have head turning. This is just for left/right though.
What I'm hoping to do is map looking up/down to the right stick (potentially even the mouse) and then cast a ray or sort of detection cone from the head which will highlight hotspots beneath.
I can cobble together some c# script to do the looking up and down bit if I make my own controller script, but is there a simple way to incorporate such a feature using AC - especially such that it can play ball with hotspots?

End goal, for context, is that the protagonist has cybernetic eyes that can be used to examine stuff or project infra-red and in gameplay terms this will serve to let the player spot stuff they can interact with from further away than normal (and maybe the occasional hidden clue.)
I'd likely tie the system to a button press (to switch on/off the super vision) but I'm not sure what the best way to go about doing ithe whole set up might be.

Comments

  • Welcome to the community, @Mcdoll.

    The "Hotspot head-turning" feature in AC is really just a reactionary visual touch - in that the character's appearance is updated when a Hotspot is selected. From what I'm gathering, what you're looking for is essentially the other way around - in which the character's head-facing affects which Hotspot is selected.

    When you say "2d worldspace", do you mean that you're specifically using the "World Space" 2D option, or just that your game is in 2D? The Settings Manager's "Moving and turning" option is what controls this.

    For custom layered animation, you'd need to first make sure your character relies on the Sprites Unity Complex animation engine. An example character prefab that uses head-turning in this way can be found on the Downloads page, but I'm guessing you've already found it.

    With Sprites Unity Complex, you can define an additional "Head pitch" float parameter in your Animator that - when updated via a custom script - affects what head animation gets played using Blend Trees / Transitions.

    A simple script could read an input axis to control it easily enough, and you could also connect it to an AC Global Boolean variable so that it only works when the Bool is set to True, i.e.:

    using UnityEngine;
    using AC;
    
    public class SetHeadPitch : MonoBehaviour
    {
    
        public string globalBoolName = "InfraRedMode";
        public string headPitchParameter = "HeadPitch";
        public string pitchInputAxis = "Vertical";
    
        void Update ()
        {
            if (GlobalVariables.GetVariable (globalBoolName).BooleanValue == true)
            {
                KickStarter.player.GetAnimator ().SetFloat (headPitchParameter, Input.GetAxis (pitchInputAxis));
            }
            else
            {
                KickStarter.player.GetAnimator ().SetFloat (headPitchParameter, 0f);
            }
        }
    
    }
    

    The wider issue would be that of selecting Hotspots, however. You could try using vicinity-based detection, but it'd be tricky to get right in 2D - I'd say it's best to use a custom system.

    If you set your Hotspot detection method to Custom Script, Hotspots then become selected through script, using:

    AC.KickStarter.playerInteraction.SetActiveHotspot (myHotspot);
    

    Which you could then call following the Raycast technique you mention.

    To swap between this mode, and regular gameplay, you can modify the detection-method at runtime. As with any Manager field, you can update it at runtime via script - just right-click its label to get an API reference to it:

    AC.KickStarter.settingsManager.hotspotDetection
    

    Just be aware that you should set this to its default/initial value in your Start function, as changes made to this will survive game restarts.

    For more on this topic, see the Manual's "Custom interaction systems" chapter and the provided "CustomInteractionSystemExample" script.

  • Thank you so much for your response Chris!
    That's exactly what I'm after - i am indeed using the world space 2d option and was imagining that because things are laid out in a way that uses the Z axis, it might make detecting hotspots kinda wonky due to the interplay between 2d and 3d.
    I'll build things using the scripts you've provided and have a fiddle with different hotspot detection methods. I expect I can build most of it to suit a 3d or 2.5d style system, but still use pixel based animations.
    Once again, thank you so much for your support and for the entire adventure creator system. It is by far and away the most straight-forward yet surprisingly robust toolkit I've used so far. It's saved me so much time on otherwise fiddly stuff like saving, loading and inventory and I've found it pretty simple to get to grips with making it play well with custom stuff so far (namely a simple equipment system running off inventory interactions and action lists to equip various gear and allow shooting like in Westwood's old bladerunner game)
    All round awesome work!
    Cheers.

  • action lists to equip various gear and allow shooting like in Westwood's old bladerunner game

    Nice! I'm sure others would love to hear details if you'd like to share more.

  • edited May 2020

    Hi Chris, one repeating issue I'm running into is in the actionlists, whenever I try to implement a "Character: Animate" action all the fields reset after assigning the character gameobject and I'm unable to modify anything.
    I assign the character game object and as soon as I click anywhere else the field resets to nothing.
    If I tick "Player" the same thing happens.
    How exactly do I ensure that the player character is the object that I want to modify with the actionlist? I watched your tutorials (particularly the 2.5d one with crouching) to see if I could emulate it, and I can't get the character to "stick" no matter what I try.

    What I've been trying to do is utilize a global boolean that will be true if the left trigger is held down on a gamepad in order to activate "aiming" which then disables character movement and activates a blendtree within which I manipulate the aiming up and down with a global float tied to the right stick's Y axis.

    Initially I had overcomplicated everything and pretty much broke my project by trying to use Unity's new input manager, but mapping new controls to that and then AC just added too many steps so I've reverted back to vanilla input manager.

    Imgur link:
    https://imgur.com/a/r5MQt8N

  • The Action needs a character to be assigned as the options that it presents are based on that character's animation engine.

    The Is Player? option causes it to refer on your game's default Player prefab - as define in the Settings Manager. If this is set, you don't need to first assign the character manually.

    If your Player character is in the scene, make them a prefab and assign them in the Settings Manager. They can remain in the scene file if you wish - but this way AC will know exactly which character you're referring to.

  • Awesome. I was a retard and deleted my player prefab somehow - I was linking the scene object but because the player character slot was empty in the ac settings it was capping out.

    For the equipment system using action lists, I use a few different animator states (duplicates of the default one) that show various guns you can carry.
    When you select a weapon in the inventory, you can choose to equip it, which calls an action list that modifies the variables I use in the animator state machine and therefore switches the sprites of the character to the ones with a weapon.
    This also changes a global variable that is tied to a custom script that controls shooting mechanics and essentially tells that script that you have a gun, which then let's you shoot/reload etc.
    If that variable is set to 0 (instead of the different gun's numbers) then the shooting controls are inactive.

    It's probably a very poor way to do it, but integrating a whole other script was pretty straightforward when using global variables as a sort of go-between. And since action lists let you change those variables as you see fit, you can therefore use them to change things like the damage a particular gun does etc.

    I'll post some examples to show folks how it all works once it's not all just default unity boxes and sprites with scribbles on them, and once I have it all working exactly as it should!
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.