- Home /
iTween sine wave like movement
Does anyone know if iTween has an inbuilt script function to move an object in a sine-wave like movement - horizontally across the screen in a straight line, but going slightly up and down at the same time? This is for a 2D game.
I've checked out the iTween reference and haven't found anything immediately obvious, I've also tried using 2 iTween.MoveTo commands one after the other in the script - the first controlling horizontal and the second vertical - but when I do this only the second MoveTo has an effect on the object. The PunchPosition looks like it might do something close - but I need a nice smooth "bobbing along" movement.
Thanks in advance for any help!
Answer by robertbu · Feb 28, 2014 at 07:07 PM
I know of no way within iTween, but you may be able to build what you want on top of iTween. That is, you send an empty game object along the path. Your visible object would be a child of the game object moving along the path. Then you attach a script to the child that moves the transform.localPosition of the object up and down. Here is a starter script:
pragma strict
var bobSpeed = 1.0;
var bobHeight = 0.5;
function Update ()
{
transform.localPosition = Vector3(0.0, Mathf.Sin(Time.time * bobSpeed) * bobHeight, 0.0);
}
I don't know enough about your game. You may have to tweak or add to handle rotation issues or any issues with synchronization.
Thanks for the reply - I'd made a start on writing a script to do it without iTween, this is very helpful. I'll give it a try now.
If you want movement without iTween and you are just moving between two fixed points, take a look at the $$anonymous$$oveObject script in the Unity Wiki either as a solution or a starting point.
Your answer
Follow this Question
Related Questions
iTween not relative to parent 0 Answers
loop a chain of iTween actions 0 Answers
C# - create an iTweenPath in the Sourcecode 1 Answer
3D Text to follow a path; iTween 0 Answers
iTween Path not realtime ?! 0 Answers