- Home /
Harmonic oscillator
Hello everyone, in my game, i'm trying to make an object whick moves as a simple harmonic oscillator. I'm using this code:
transform.position += (moveDirection+Vector3(0,A*Mathf.Cos(Time.time),0)*movementSpeed)*Time.deltaTime*60;
the moveDirection Vector is the normal motion he'll have, and the other one's y component it's varying with the Mathf.Cos of the Time.time variable, so an harmonic motion it's done.
When I run the game with the editor it works fine, but it seems to be something related to that Time.time part, because when i build the game's executable, it just doesn't work as I expected (it follows a different path).
What am I doing wrong?
Thank you
I've found it. Time.time it's actually the time elapsed since the game started, not the time since the level was loaded, so the starting value for Time.time was different between the editor and the game because this wasn't the initial level.
Then you should 'answer' your question so folks don't need to worry about it, or close it.
Answer by Setzer22 · Nov 01, 2011 at 05:20 PM
Here's the answer I found out:
I've found it. Time.time it's actually the time elapsed since the game started, not the time since the level was loaded, so the starting value for Time.time was different between the editor and the game because this wasn't the initial level.
Your answer
Follow this Question
Related Questions
2d cannon bullet 3 Answers
2D jerky motion with AddForce and physics. 1 Answer
Reverse and Backpedal 1 Answer
How do I make my Instantiated prefab go where my game object moves ? 2 Answers
Enemy shooting problem 0 Answers