March 01, 2016

How to move object following sine curve in Unity?

Today I solved little task of moving objects following given direction. In my case it was sine curve.

Scene setup.

There are minimal set of objects on scene: camera, light, cube and sphere. Camera rotated by 90 degrees around X axis and lifted up by Y axis, so we're watching scene vertically. Cube has Rigidbody attached; property Use Gravity is disabled on it. Sphere has just a regular SphereCollider.

Mathematical background.

We want to move
Cube to Sphere adding sinusoidal vibration perpendicularly to the moving direction. At the beginning we need to calculate vector of moving direction and orthogonal vector for it. We will multiple orthogonal vector by result of sinus function (time is an argument).


Attach script Mover to Cube object. In the Start() method we will save both vectors and start time. Finally, the main magic is here in single line of code of FixedUpdate() method. We need calculate magnitude of orthogonal vector using classical formula of periodical vibration: y = a * sin(w*x), where a - is amplitude of vibration, w - is frequency of vibration, x - is time in our case. After that we will perform addition of two vectors and assign to Rigidbody.

That's all! You can download all sources from Github.


  1. I appreciate you to share such news which is helpful for a developer who has to develop new business website.I am not interested in it because I have been marketing for dissertation writing service

  2. Those looking for someone asking to " Do my assignment" can reach out to our dedicated team of experts who have relevant qualifications for writing your assignments. We have extensive knowledge and use of experience in providing assistance on various subjects and topics with well-structured content and completely referenced papers.

  3. Ok mad men ikke noget særligt. Vi fik rejer, lam og kylling. Dyre drikkevarer. F.eks. koster en lille mango lassi 50 kr. og en chai the det samme - den var i øvrigt ikke særlig godt. Betjeningen sød og opmærksom.

  4. Getting Psychology Homework Help is the ideal solution for any problems that students may have. Numerous advantages make it one of the most excellent options because it assists students in various ways.

  5. The most common way of moving objects in Unity is to set transform. position to a Vector2 or a Vector3. This will change the position of the GameObject that holds the component from which the code is called from. But it is also possible to call transform.
    Dissertation Writing Services

  6. Very useful article for a java programming help professionals, they can easily enhance their skills in coding and hacking with this kind of information.