2D EntityFollower rotates transform when setting destination

  • A* version: 5.4.5

  • Unity version: 6.2

    Movement script:

        // Mouse click input (client only)
        public void OnAutoWalk(InputAction.CallbackContext ctx)
        {
            if (!isOwner || (!ctx.performed && !ctx.canceled))
                return;

            Vector2 mousePos = Mouse.current.position.ReadValue();
            // Check if mouse is inside the camera render area (ignores letter bars)
            if (!_mainCamera.pixelRect.Contains(mousePos))
                return;

            // Check if mouse is over UI
            if (IsPointerOverUIObject(mousePos))
                return;

            Vector3 worldPos = _mainCamera.ScreenToWorldPoint(mousePos);
            worldPos.z = 0;
            Debug.Log("Setting destination to: " + worldPos);
            _agent.destination = worldPos;

        }

I’m getting in the console:

Setting destination to: (39.39, -28.46, 0.00)

I tried to disable all the rotation, but the player doesnt walk, because it is trying to move in the Z axis.

I’m not seeing this behavior on my end. I set up a simple 2D scene and turned off Rotation Sync and my agent stays looking the way it started, no issue.

A little confused here. Your agent and graph are both 2D but they’re trying to move on the Z axis? I guess for starters I’d set your Recast Graph’s center Z to 0 and make sure your agent is also Z = 0. I don’t know if that would have any bearing but it’s worth a shot.

Otherwise if you can provide more information or visual examples that may help a lot.

Ok I managed to stop rotating the agent by setting this:

image

Not sure why before, even with the same setting it wasn’t work.

Game dev in a nutshell. Glad you got it working :slight_smile: