Forum rules - please read before posting.

2D: Turning transitions trigger too often + character offset + overly sensitive movement direction

Hey everyone,

I'm working on a 2D game in Unity 6 (Unity 6000.0.42f1 ) using the newest Adventure Creator version.
I have a few issues I'd like to ask about – one of them is shown in a short video I'm linking below.

  1. Transition passes through in-between directions when switching sides
    When I move from one direction to its opposite – like from Left to Right, or from Up to Down – the Animator briefly switches to the in-between direction, instead of directly playing the correct target animation (e.g. Walk_Left to Walk_Right).

You can clearly see this behavior in the short video I attached.

youtu.be/3nQhrTb6l9k

→ I'd like to know if it's possible to transition directly to the target direction (e.g. from Walk_Left to Walk_Right), without going through an intermediate state like Down or Idle.
Are there recommended settings or techniques for handling this kind of directional switch in Adventure Creator?

  1. Character stands too high above the clicked point
    My player character seems to always stand a little too high above where I click.
    Their feet never align exactly with the point I click on the floor.

I know I could move the capsule collider lower, but I'd rather ask:
→ Is there a recommended way to make the click target adjust automatically, so that the feet are placed more naturally at the click point?

  1. Movement direction too sensitive – I'd like a Y-tolerance
    When clicking to move only left or right, the character often moves slightly up or down if my click isn't perfectly aligned on the same Y axis.
    This makes the movement feel overly sensitive.

→ Is there a way to set a “tolerance” for vertical offset, so that small Y differences are ignored?
For example, if the Y difference is less than 15 pixels (or units), I'd like the character to move purely horizontally instead.

Thanks a lot in advance – I appreciate any tips or recommendations on these three points!

Best,
LytonLight27

Comments

  • Transition passes through in-between directions when switching sides

    If you're looking to disable turning, so that he snaps to the given direction, you can set his Turn speed to -1.

    Character stands too high above the clicked point

    You'll need to ensure their root object position is around their feet. With 2D characters, this is typically done by positioning each sprite's Pivot point so that it's around the character's feet. Then, when attached as the character's Sprite child with a local position of (0,0,0), they'll appear to be in the correct position.

    Movement direction too sensitive – I'd like a Y-tolerance

    It's possible to "flatten" a character's path through scripting. An example script can be found on the AC wiki:

    https://adventure-creator.fandom.com/wiki/2D_point_and_click_along_one_axis

    It'd be possible to have this run only if the change in Y position is less than a set distance - but pathfinding is an issue. Changing points on a navigation path can cause them to come off the NavMesh if you're not careful.

    What you'd need to do is check each point on the path separately, and only adjust it if the "flattened" position is still on the NavMesh.

    This should do it. Place in the scene, and assign the NavMesh's collider in its Inspector:

    using UnityEngine;
    using AC;
    
    public class FlattenPathfinding : MonoBehaviour
    {
    
        public float yThreshold = 0.2f;
        public PolygonCollider2D navMesh;
    
        private void OnEnable() { EventManager.OnCharacterSetPath += OnCharacterSetPath; }
        private void OnDisable () { EventManager.OnCharacterSetPath -= OnCharacterSetPath; }
    
        private void OnCharacterSetPath (AC.Char character, Paths path)
        {
            if (character == KickStarter.player)
            {
                for (int i = 0; i < path.nodes.Count; i++)
                {
                    Vector3 previous = (i == 0) ? character.transform.position : path.nodes[i - 1];
                    float yDiff = Mathf.Abs(path.nodes[i].y - previous.y);
                    if (yDiff > yThreshold) continue;
    
                    Vector3 newPoint = new (path.nodes[i].x, previous.y, path.nodes[i].z);
    
                    if (Physics2D.OverlapPoint(newPoint) == navMesh)
                    {
                        path.nodes[i] = newPoint;
                    }
                }
            }
        }
    
    }
    
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.