Search Unity

GameObject follows mouse but need some delay!

Discussion in 'Scripting' started by chiragchopra, Sep 23, 2013.

  1. chiragchopra

    chiragchopra

    Joined:
    Sep 23, 2013
    Posts:
    4
    Hey,

    I using the code below to make the GameObject follow the mouse pointer, but the problem is, it's very instant! I want some delay in the object to start following the pointer. And maybe the object increases its speed eventually to follow the pointer. Here's the code:

    Code (csharp):
    1. var depth = 10;
    2.  
    3.  
    4. function Start ()
    5.  
    6. {
    7.  
    8.      Screen.showCursor = false;
    9.  
    10. }
    11.  
    12.  
    13. function Update ()
    14.  
    15. {
    16.  
    17.      var mousePos = Input.mousePosition;
    18.  
    19.      var wantedPos = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, depth));
    20.  
    21.      transform.position = wantedPos;
    22.  
    23. }
    Can someone help me?