need help with basic enough c# coding, unsure. (Newbie)

basically i’m trying to make a code where if the players position is further along on the z axis then the randomly changing obstacles will move along the ground block for the next wave of dodging, if that makes sense.
if you need anymore info let me know, im sorry that im not much help, its my first game.
Thanks in advance.

First, don’t use “position” as itself. It’s a Vector3, a combination of 3 flats (individual value), and What you are asking for is the value of “player.position.y” or “position.x”.

Are you trying to make blocs appear or displace in front of the player ?

If you just need the obstacle to follow exactly the player postion, you can use in your Update :

void Update(){
gameObject.transform.position.z = player.position.z;

if you need it to be in canals or fixed positions, create several empty GameObjects so you can take their positions :

if (player.position.x > 0 && player.position.z < 2) {
gameObject.transform.position = Exemple1.transform.position;
} else if (player.position.x > 2 && player.position.z < 4) {
gameObject.transform.position = Exemple1.transform.position;

the “&&” sign means “AND”, so it basically ask you to be in a certain range to aply to one or the other. You can repeat the operation as much as you wish.

With this you should be fine to start. If you want things to slide, you can search for a displacment in Update, with speed*Time.DeltaTime. Look for it a bit, I’m sure you should find it quickly :slight_smile: