Search Unity

Need help at making object follow player.

Discussion in 'Scripting' started by DrunkGamer, Aug 16, 2013.

  1. DrunkGamer

    DrunkGamer

    Joined:
    Aug 6, 2013
    Posts:
    4
    I have a little big problem. I'm making a game and i need an object to follow the player when not seen, everything is working fine except for 1 thing... The object moves trough the floor, walls and everything on it's way without giving a single F*** about it (like a baws). I think it's because the script ignores phisics, but i can't find a way to make it work.

    Here is the script:

    Code (csharp):
    1. #pragma strict
    2.      var player : Transform;
    3.    
    4.      var statue : Transform;
    5.    
    6.      var speed : float = 0.5;
    7.      
    8.      var RockDragging: AudioClip;
    9.        
    10.     function Update(){
    11.    
    12.      if(renderer.isVisible == false){
    13.    
    14.          statue.LookAt(player);
    15.  
    16.          statue.Rotate(player);
    17.          
    18.          statue.Translate(speed*Vector3.forward);
    19.          
    20.          audio.clip = RockDragging;
    21.          
    22.          audio.Play();
    23.          
    24.         }
    25.    
    26.     }
    27.    
    28.     function OnBecameVisible() {
    29.    
    30.          audio.clip = RockDragging;
    31.    
    32.          audio.Pause();
    33.          
    34.     }
    If you could post an example code of how to make it work, it's much appreciated.
     
  2. Kray-C

    Kray-C

    Joined:
    Apr 8, 2013
    Posts:
    152
    I am not exactly sure what you want to do, but if the thing is running through walls I would say first add a collider.
     
  3. Kryber

    Kryber

    Joined:
    Apr 14, 2013
    Posts:
    92
    Yes I quote Kray-C .... Try giving to "statue" a Collider