Moving objects changing their position when I start the game.
Hi everyone! I have a 3D platform game and I made some moving platforms. The problem is that these moving objects change their default position when I play the game or build it then play it, but they do that only when it loads in a new scene. When I start the game in Scene 2, everything is fine but when the scene manager loads the Scene 3, its moving game objects are start the moving from a different position. Let me show an example: I make a cube and set its position to (0,0,0). I want it to levitate and rotate so I write a script like this:
Vector3 v;
public float Ampl = 0.5f;
public float Rspeed = 3.0f;
void Start()
{
v = this.transform.position;
}
void Update()
{
this.transform.Rotate(0, Rspeed, 0);
v.y += Ampl * Mathf.Sin(Time.time * Rspeed);
this.transform.position = v;
}
The rotation works fine but the moving in axis y starts in (0,0,0) only when I press the play button in the scene where the cube is. If a previous scene loads in this one, the cube starts its levitation not from y=0 but from a different y position, for example y = -2. This is the same situation with moving objects in axis x and z with Mathf.Sin. Has anyone an idea what should I do with this problem? Thank you for your help!
Your answer

Follow this Question
Related Questions
ridgidbody AddForce in direction player is pointed? 1 Answer
Move Character to touched Position 2D (Without RigidBody and Animated Movement) 1 Answer
Player (box) movement is shaky (visual only) 0 Answers
My character doesn't move. How should I do? 1 Answer
How could I make an object move from left to right and it will come back from right? 0 Answers