Constrained Movement Path

Okay. So I’m trying to create movement similar to the old atari game “Warlords” in that the player and enemies can only move within a small L shape of space and when they reach that corner they rotate around it.

I’ve created an image to illustrate:

2297444--154596--Movement.png

Yea… it’s an extremely simple illustration, but I hope it helps what I’m trying to say.

I would use Mathf.Clamp but that would restrict it from making the L shape…

Any thoughts would be appreciated.

I’ll note I’m on 5.1.1f1 and use C#, also this project is in 2D. In case it’s helpful I’ll share my player movement script

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

    public float playerSpeed;
    public Vector3 playerPos;

    // Use this for initialization
    void Start ()
    {
    
    }

    // Update is called once per frame
    void Update ()
    {
        float yPos = gameObject.transform.position.y + (Input.GetAxis("Vertical") * playerSpeed);
        playerPos = new Vector3 (-10,Mathf.Clamp (yPos, -9,9),0);
        gameObject.transform.position = playerPos;
    }
}

Yes… currently the only possible movement in my game is up and down… haha…

L shape? Do you mean 4 way movement, 8 way movement or grid movement?
4 way movement is when you can only move into 4 directions(up, down, left, right) but you can stop whenever you want
8 way movement is the same but it allows diagonal movement
grid movement is when you move 1 tile at a time in a 4 way direction

Please notice the illustration in the first post as it explains pretty simply what I’m attempting.

I call it “L shaped” because they can ONLY move along the L, not inside the L or outside the L. Think of an amusement ride, the car has to follow the rail. I simply want to put the player and cpu on a rail they can move about on.

To iterate even more, I wouldn’t like this to have four movement keys. Ideally if you’re at the bottom of the L, and you press Up (or W) you won’t move, however if you hit Left (or A) You’d go up and then proceed left once making the turn. ← Same movement style to the game Warlords by Atari.

I am not sure this is the best solution but…

How about using multiple bounding boxes or triggers to represent the allowed movement area and only permitting movement if the new location is within those zones.

It would allow any shape of stage right?

That was my initial thought as well. And jaggy movement and jerky twitching when trying to push outside the boundry aside, due to the way using tiggers and bounding is, it wouldn’t be able to rotate the Player on the corner or even make the turn of the corner for that matter.

However, if this was a wider “L” with more ability to move left and right on a section of the “L”, then it’d work. However, I need them to only be able to move exactly on the “L”

Ah on rails then. If that is the case I would have a collection of waypoints and as the player moves, lerp to each waypoint. Either the next or previous waypoint. When the player arrives you update which waypoints they can move to.