Free 'Weeping Angels' eqsue script

Discussion in 'Assets and Asset Store' started by suctioncup, Aug 19, 2012.

  1. suctioncup

    suctioncup

    Member

    Joined:
    May 19, 2012
    Messages:
    266
    Ok, this script moves an object when it is not seen by the camera.
    NOTE: This only works when the object is not seen in the scene view.

    http://pastebin.com/Te9ZxL3D

    Code (csharp):
    1. #pragma strict
    2.  
    3. /*
    4. COPYRIGHT 2012 SUCTIONCUP, RELEASED UNDER CREATIVE COMMONS, USEAGE ALLOWED IF YOU CREDIT SUCTIONCUP
    5. */
    6.  
    7. //target to follow
    8.  
    9. //Checks his position, used to follow the target
    10. var pos : Transform;
    11.  
    12. //Ray variables (Length... etc.)
    13. var rayLength : float = 3;
    14.  
    15. //Movement, speed etc.
    16. var speed : float = 2;
    17.  
    18. //You can move if he is not being looked at
    19. var move : boolean = false;
    20.  
    21. //I had problems with my model sinking into the floor, adjust this variable if you need it, or remove it
    22. function FixedUpdate()
    23. {
    24. transform.position.y = 2;
    25. }
    26.  
    27. function Update()
    28. {
    29.     //Setting up Raycast variables for simple object avoidance
    30.     var fwd = transform.TransformDirection (Vector3.forward);
    31.     var hit : RaycastHit;
    32.    
    33.     //If you are looking at the object...
    34.     if (renderer.isVisible)
    35.     {
    36.     move = false;
    37.     }
    38.    
    39.     //If you are NOT looking at the object...
    40.     if(!renderer.isVisible)
    41.     {
    42.     move = true;
    43.     }
    44.  
    45.     //If you are not looking at the object...
    46.     if(move)
    47.     {
    48.     //Make him look at the target
    49.     transform.LookAt(target);
    50.     //Always follow the target
    51.     pos.position += pos.forward * speed * Time.deltaTime;
    52.     }
    53.    
    54.     //If he is 3 units away from something, move right (Works if you are not looking at the object)
    55.     if (Physics.Raycast (transform.position, fwd, rayLength)  move)
    56.     {
    57.     Debug.Log("Something ahead, moving");
    58.     transform.Translate(Vector3.right * 3 * Time.deltaTime);
    59.     }
    60.  
    61. }
    If there are any problems, just ask. Have an idea on how to improve the script? Just say.
    Last edited: Jun 27, 2013
  2. fholm

    fholm

    Member

    Joined:
    Aug 20, 2011
    Messages:
    1,634
    You do realize that CC licenses are intended for works of art and are not really that compatible with code.
  3. Scott M

    Scott M

    Member

    Joined:
    Jul 13, 2005
    Messages:
    23
    That's just not true, CC licenses are perfectly valid for code. In fact on the CC site it says "Looking for music, video, writing, code, or other creative works?"
  4. christianmanners

    christianmanners

    Member

    Joined:
    Jan 31, 2013
    Messages:
    7
    im using a humanoid model and when the game starts the model hovers a little bit above ground i tryed rigibody but it no work pls help?
  5. wccrawford

    wccrawford

    Member

    Joined:
    Sep 30, 2011
    Messages:
    1,581
    Code (csharp):
    1. //I had problems with my model sinking into the floor, adjust this variable if you need it, or remove it
    2.  
    3. function FixedUpdate()
    4.  
    5. {
    6.  
    7. transform.position.y = 2;
    8.  
    9. }
    Change that.