Instantiation problem

Hi I have an script which instantiate a cube. I want that cube to go up a bit, and then fall down, without changing the x and y coordinates. How can I do it?

I suppose you’ll want to use the Transform.Translate method and only supply values for Z:

Yes that would be a simple way to solve it but I forgot to say something. The game is a top down puzzle game. I want the object to go forward and then backward. :smile:

The direction of your axes is not relevant, just move it along the appropriate axis for the view and be done with it. If your X axis is up and down on the screen, going into the screen, or horizontal it doesn’t matter as long as your view and simulation space present things as you desire.

Yes but I want it to collide with another object at the bottom of the screen. *My Y axis is up and down on the screen not the X one.

Good job on having your Y axis as up, if you want to move it on that axis, move it on that axis. Fizix pointed you to the Transform component which covers how to do this.

I dont get you at all…

myCube.transform.Translate(new Vector3(0, 5.0f, 0)); //will move the cube 5 units “up”

myCube.transform.Translate(new Vector3(0, -5.0f, 0)); //will move the cube 5 units “down”

Thank you!

Do you realize that will change the y-coordinates?

Yeah, I’m pretty sure he was saying that was his “up” for his game.

Yes but for some reasons I tough it wont work if I put 2 translate lines one before the other :smile: