- Home /
How to make moving tiles in side scroller?
I have a tile prefab. The user has to jump from tile to tile. I want to know how to make a script so that if attached to a tile, it will make that tile move back and forth along the x Axis. How would I do this?
Answer by Kiwasi · Aug 13, 2014 at 12:12 AM
private bool movingLeft;
void Update (){
if(transform.position.x < -4){
movingLeft = false;
}
if(transform.position.x > 4){
movingLeft = true;
}
if(movingLeft){
transform.Translate(Vector3.Left);
} else {
transform.Translate(Vector3.Right);
}
}
Yes, that would make it move. But. It would have to stay at (-4,0,0) to (4,0,0) Since its a side scroller eventually the character will be at lets say (100,0,0). So that tile will be wayy off screen. I guess I should have provided more specific information. I am trying to store its current position in a local variable and just add x amount. But having trouble.
Then make the floats variables, set them based in the start method, based on transform.position.x
Your answer
Follow this Question
Related Questions
How to lerp back and forth? (ex. platform) 2 Answers
Need help with a relatively simple issue. 1 Answer
Player Controls 0 Answers
Character Keep On Moving Without Pressing Button 0 Answers
Move an object from A to B to C etc.? 2 Answers