Forum rules - please read before posting.

Limit 3D character movement to only 2 directions?

edited March 29 in Technical Q&A

Hey everyone! I'm new to Unity and Adventure Creator, and I’m working on a Greek Shadow Theater-inspired game.

Project atm

Please view this to get a better ideas of the setup:
Scene screenshots/settings/video in action: https://imgur.com/a/rgm0h0n

My setup:
Latest version as of 29th March 2025, both Unity and AC.

Animation engine: Mecanim
Movement Method: Direct Control
Input Method: Keyboard or Controller
Direct-Movement Type: Relative to Camera
Movement Limitation: Four Directions
Turning Mode: Independent
Rigidbody Settings: Move with Rigidbody enabled, Rotation Frozen
For Pathfinding I've tried all, only Polygon and Mesh Collider work I think

I’ve frozen rotation, which seems to half-work, but I’m running into some issues and looking for advice on how to best handle this.

How can I restrict movement to only Left and Right?
I read in other posts that people were successful by using Player: Constrain , but I've set it up and when using Character: Move to Point, I'm still having issues. Fixes my direct movement issues though.

For now, I don’t need an animation to play when turning—I just want to prevent any unwanted rotation. What’s the best way to make sure Adventure Creator doesn’t try to turn my character at all? Right now, the only way I’ve managed to stop it is by setting the character’s turn speed to 0, which obviously isn’t the right solution but somehow works for now.

Please be kind and consider I've only have at most a month of Unity experience and have worked on this for only a few hours as I was mostly learning by doing!

Thanks in advance!

Comments

  • Welcome to the community, @ioannis.

    Love the idea! Very unique style and looks a lot of fun.

    Setting the Turn speed to 0 is the intended way to prevent AC from turning the character. Are you having further issues with this set?

    If so, it is possible to enforce the character's rotation by setting it in LateUpdate in a custom script. I can help with that if it's needed.

    Your Settings Manager show that yours is a 3D game. As your characters can only move sideways across the stage, you can likely do away with a NavMesh, and just uncheck Pathfind? in any Character: Move to point Actions. To block the Player's ability to move off-screen, place down Colliders either side of the stage.

  • edited March 30

    Hmm setting or unsetting Pathfind? in Character: Move to point actions doesn't change anything really. I did have Retro-style movement enabled but it seems the Player won't move at all now- like they are stuck :disappointed:

    I did set a default NavMesh and created a mesh at the bottom of the character- as well as set Pathfinding method to Mesh Collider.

    Stuck

    So... I just did a test with an NPC cube :D
    Set it up so it moves the same way. Tested Character: Move to Point , and it seems like it turns first then goes to the point. If I put Turn speed 0, it just gets stuck like my character. Not entirely sure on how to proceed though :neutral:

  • Ultimately, if your configuring the game as being 3D, then characters will attempt to turn towards their movement direction.

    If that's the main issue here, then what you can do is move the visual aspects of the character (Animator, Skinned Mesh Renderer etc) to a child object, and then have a script counter-rotate this child. Essentially, let the base object turn, and have the child turn the other way so that it always faces the correct way.

    It's a simple script. Try this. Create a new C# file named ForceFaceDirection, copy/paste in the code below, and then attach the new Force Face Direction component to the child object created as above:

    using UnityEngine;
    
    public class ForceFaceDirection : MonoBehaviour
    {
    
        public Vector3 direction = new Vector3 (0f, 0f, -1f);
    
        void LateUpdate ()
        {
            transform.rotation = Quaternion.LookRotation (direction, Vector3.up);
        }
    
    }
    
  • Thank you for taking the time explaining. I appreciate it.
    I understand the logic behind this and I will have to test thoroughly a little later today but just giving this a quick test-drive, it might actually be harder than it looks to make it work.

    This is my character:

    Character

    The MainController is the RigidBody that drives the rest of the body of the character through Hinges. It's all driven by physics so I'm afraid just changing the transform rotation might cause issues and I'm also not entirely certain where the script should be placed in this arrangement. I quickly tried to set the script to the Body parent (it's an empty parent) but had very weird results.

    If you have any additional input consider what I'm sharing now, let me know, but I'll still come back later today with my experimentation on this!

    Thanks again.

  • Yup using the script on the Body... leads to various issues.

  • Don't attach the script to any existing objects. Instead, create a new Empty that's an immediate child of Karagiozis, and attach it to that. Make sure that it's local position is 0,0,0.

    Then, make MainController and Body both children of this new Empty. Does that resolve it?

  • Thank you Chris! It seems to have worked! I still had to figure out some freeze position on some RigidBodies I missed but it works!

    Thanks again.

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.