Moving an object along a cosine curve...

Hello. I am trying to make an object move along a cosine curve. This first script is one that moves an object along a sine curve (I modified it from something I got on the forums). When I try to modify it again (as seen in the second script), I run into some problems. As of now, if I set the Height variable to 3, the object’s y transform value immediately moves to 3, dips down to -3 and then goes back up. How can I shift the curve so that I can the object stays at 0 at the start, dips down to -3, and then rises back up to 0. I have tried using Mathf.clamp to stop the value from rising past m_centerPosition.y…but it just gets ignored. What am I doing wrong? Thanks.

private var m_centerPosition:Vector3; 
private var m_degrees:float = 0; 
private var m_speed :float = 1.0f;
private var m_period:float = 1.0f;

var Count : float;
var Speed : float;
var Height: float;

function Start (){
	//16.7 is the world space that it takes to complete the Count Cycles. 
	m_period  = 16.7/Count;
	m_speed  *= Speed;
	m_period /= Speed;
	m_centerPosition = transform.position;
}

function Update(){
	m_centerPosition.x += Time.deltaTime * m_speed;
	var degreesPerSecond:float = 360.0f / m_period; 
	m_degrees = Mathf.Repeat(m_degrees + (Time.deltaTime * degreesPerSecond), 360.0f);
	var radians:float = m_degrees * Mathf.Deg2Rad;
	var offset:Vector3 = Vector3(0.0f, m_centerPosition.y+Height * Mathf.Sin(radians), 0.0f); 
	transform.position = m_centerPosition + offset;
}

The Cosine Script.

private var m_centerPosition:Vector3; 
private var m_degrees:float = 0; 
private var m_speed :float = 1.0f;
private var m_period:float = 1.0f;

var Count : float;
var Speed : float;
var Height: float;

var Offset: float;

function Start (){
	//16.7 is the world space that it takes to complete the Count Cycles. 
	m_period  = 16.7/Count;
	m_speed  *= Speed;
	m_period /= Speed;
	m_centerPosition = transform.position;
}

function Update(){
	m_centerPosition.x += Time.deltaTime * m_speed;
	var degreesPerSecond:float = 360.0f / m_period; 
	m_degrees = Mathf.Repeat(m_degrees + (Time.deltaTime * degreesPerSecond), 360.0f);
	var radians:float = m_degrees * Mathf.Deg2Rad;
	Offset = (m_centerPosition.y- Height) * Mathf.Cos(radians); 
	transform.position.y = m_centerPosition.y + Offset;
}

Looks like the original script has an error. The centerPos on line 23 should be gone (it gets used in line 24, and don’t want to add it twice.) Of course, with centerPos set to 0, it won’t matter.

A standard sin (or cos – they both look the same) moves up and down by the amount (normally 1, but Height in that code) from a centerPos. To go from -3 to 0, start it at -1.5 (exactly centered between -3 to 0,) and set the Height to 1.5.