r/UnityHelp • • Mar 17 '22

Quads in unity.

Sorry for my noob question but i'm working in a little game "endless runner" so i just created 2 quads with the ground and background material with the speed animation scripts and it works prefectly but the thing is that im setting my player to run right and i gave him a speed but he can quit the ground n background scene i want him to run "right n left" freely but inside the ground scene without passing it.

2 Upvotes

1 comment sorted by

1

u/Sharkytrs Mar 18 '22

place your character at the extreme edges of the landscape (where you want the limits to be) note the position on the axis you want to limit.

wrap your movement code for horizontal movement in an if statement that is only true when the players transform axis value lies between this range.

i.e.

if(player.transfom.position.x < 80)

{

Right move stuff;

}

if(player.transform.position.x > 20)

{

Left move stuff;

}

would limit the player between 20 and 80 on the x axis

remember to keep other stuff outside the loop, only the control you want limited should be there, not for instance jump, as when it gets to this limit the control just stops for that direction and the player cant move more.

there are many ways to do it, this way at least allows the model to be pushed off limit by other things, but can still move back