Changing motion of start state of Controller in runtime

I am working on a 2D game in which dungeons are generated in runtime. Now each room in the dungeon can have door at North, South, East or West randomly.

If the player is exiting Room1 from South, the next scene should have the player in Room2 near the North door with Direction facing the room.

I am able to achieve all the steps above except facing the room dynamically.
If player exits Room1 from east, player should be facing east of Room2 and so on.

I have Controller created for movement with a Default state But right now the Default state has a Motion that is assigned from inspector.

How do I assign Motion to this Default on runtime? I have tried AnimatorOverrideController but there is no change in Motion field.

The Controller:
8509931--1133834--Controller.PNG 8509931--1133837--Default state.PNG

My PlayerMovement script handles the animation of the Player

public class PlayerMovement : MonoBehaviour
{   
        public AnimationClip[] clip;

    protected AnimatorOverrideController animatorOverrideController;

    void Start()
    {
        dir = GetDirection();
        Debug.Log("Dir is " + dir);
       
        animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
        animator.runtimeAnimatorController = animatorOverrideController;
        animatorOverrideController["Default"] = clip[dir];
    }
}

Player inspector:

Thanks in advance.

Right now you have the player “picking up” the position of the new entrypoint in the next room… best way is always to obtain that from an empty GameObject (via Transform) that you inject into the created level when you’re done.

Then it is easy to rotate that invisible object to face “into” the room, and have the player “pick up” rotation as well as position.

Also, +1 for procedural dungeon game. :slight_smile: