Hello, Is it possible to make a script that smoothly moves an object up and after a few seconds down again?
Thanks, Andreas.
Hello, Is it possible to make a script that smoothly moves an object up and after a few seconds down again?
Thanks, Andreas.
A really quick and dirty way to achieve this would be to just move the objects y axis along a sine curve. I.e.:
var Step : float; //A variable we increment
var Offset : float; //How far to offset the object upwards
function Start () {
//Store where we were placed in the editor
var InitialPosition = transform.position;
//Create an offset based on our height
Offset = transform.position.y + transform.localScale.y;
}
function FixedUpdate () {
Step +=0.01;
//Make sure Steps value never gets too out of hand
if(Step > 999999){Step = 1;}
//Float up and down along the y axis,
transform.position.y = Mathf.Sin(Step)+Offset;
}
Easier than iTween (Not that is particularly hard …), there is still Mathf.Lerp / Vector3.Lerp.
Oh, and checkout that link if you want to continue with iTween : http://wiki.unity3d.com/index.php?title=ITweenX