- Home /
"Hover" object up and down
Hello, Is it possible to make a script that smoothly moves an object up and after a few seconds down again?
Thanks, Andreas.
It is possible :) An easy solution would be using iTween (http://itween.pixelplacement.com)
Answer by o_oll · Nov 11, 2012 at 05:33 AM
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;
}
any idea how to increase the size of the sine curve so the object moves up higher and moves down lower?
Answer by FakeBerenger · Nov 10, 2012 at 10:41 PM
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
Your answer
Follow this Question
Related Questions
Move up and down one arm 1 Answer
Slowly speed something up to a top speed after a specified amount of time? 0 Answers
How can i move a game object up and down so it acts like a obstacle for my sphere player 4 Answers
How should I move an object that parents on collision? 1 Answer
using Transform on a Object will not move it 100% exactly... 1 Answer