Restrict movement inside trigger

Hello all

I’m a unity newbie

I am trying to restrict movement inside a trigger

once the player touches the edge of the trigger to stop moving and I want to restrict the axis they play can move while in the trigger

I have a trigger set just in front of wall of object currently I have the camera changing only when trigger is active and the right mouse button is clicked

the trigger is the same dimensions as the wall object

Hard to know how you controller script is setup but just set a bool that goes to true when inside the trigger collider, looks like it’ss wall related so let’s call the trigger wallTrigger.

Then in you controller script just check if wallTrigger = true and affect how the player can control the character e.g.

if(wallTrigger)
{
    // do restricted movent here
}
else
{
    // do normal movement nere
}

you’re collider script will need a reference to the controller script (I’ll call this myController as I don’t know what your script is called)

private myController theControlScript;

Then in OnTroggerEnter/OnTriggerExit…

OnTriggerEnter()
{
    theControlScript.wallTrigger = true;
}

OnTriggerExit()
{
    theControlScript.wallTrigger = false;
}

You will need that wallTrigger being public so at the top of you control script

public bool wallTrigger;

All examples in C#