cosine wave

Im trying to make an object following the path of a cosine wave… And when the object reaches the end of the wave, I want it to return via the same exact path. Problem Ive had is the object follows a slightly different wave path on the way back… I think its because I am not sure how to determine the wavelength… and send the object back when it hasnt quite reached its original X axis.

[code]

local frequency = 100
local amplitude = 15

local continue = true
local function moveOrb()

if orb1.y <= 960 and continue == true then
orb1:translate( (math.cos( system.getTimer() / frequency ) * amplitude), 10 )
else
continue = false
end

if orb1.y >= 0 and continue == false then
orb1:translate( -(math.cos( system.getTimer() / frequency ) * amplitude), -10 )
else
continue = true
end

end

Runtime:addEventListener(“enterFrame”, moveOrb) [import]uid: 28912 topic_id: 8940 reply_id: 308940[/import]

I think if you kept track of the timer yourself, and reset it to zero at the start of the journey, and at the start of the reverse journey, you’d see the exact same path. Using the system timer isn’t what you want here I think. Even being off by a few microseconds will give you a different path on the way back. [import]uid: 8673 topic_id: 8940 reply_id: 32693[/import]

I tried creating my own timer, but still cant get the object to follow the same path back and forth. I think I just need to know what the wavelength is? And am not sure how to calculate it. And then I could change this line of code

if orb1.y \<= 960 and continue == true then  

to this

if orb1.y \<= wavelength and continue == true then  

[import]uid: 28912 topic_id: 8940 reply_id: 32969[/import]

Isn’t wavelength = speed / frequency?

Not sure if that helps… [import]uid: 48521 topic_id: 8940 reply_id: 33045[/import]