How to make Object follow in y-axis with distance scale

Hello!

Here is the problem:
I have made my object1 to follow object2 in y-axis and x-axis but it should move a little bit in y-axis in terms of object2 like -2 to 2.

Something like this:
[![[/URL]

Any ideas how to solve this? Using JavaScript

Here is the code so far:

  • var Player :GameObject;
    • functionUpdate(){
  • transform.position =newVector3(Player.transform.position.x - 0.3, Player.transform.position.y, transform.position.z);
  • }
    ](http://s14.postimg.org/g7e0sapz1/prob1.jpg "[/URL]

Any ideas how to solve this? Using JavaScript

Here is the code so far:

  • var Player :GameObject;
    • functionUpdate(){
  • transform.position =newVector3(Player.transform.position.x - 0.3, Player.transform.position.y, transform.position.z);
  • }
    ")](http://postimg.org/image/g7e0sapz1/)

Ok, solved the problem… theres distance joint 2d in unity physics 2d…