Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Free 'Weeping Angels' eqsue script

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

  1. suctioncup

    suctioncup

    Joined:
    May 19, 2012
    Posts:
    273
    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. var target : Transform;
    9.  
    10. //Checks his position, used to follow the target
    11. var pos : Transform;
    12.  
    13. //Ray variables (Length... etc.)
    14. var rayLength : float = 3;
    15.  
    16. //Movement, speed etc.
    17. var speed : float = 2;
    18.  
    19. //You can move if he is not being looked at
    20. var move : boolean = false;
    21.  
    22. //I had problems with my model sinking into the floor, adjust this variable if you need it, or remove it
    23. function FixedUpdate()
    24. {
    25. transform.position.y = 2;
    26. }
    27.  
    28. function Update()
    29. {
    30.     //Setting up Raycast variables for simple object avoidance
    31.     var fwd = transform.TransformDirection (Vector3.forward);
    32.     var hit : RaycastHit;
    33.    
    34.     //If you are looking at the object...
    35.     if (renderer.isVisible)
    36.     {
    37.     move = false;
    38.     }
    39.    
    40.     //If you are NOT looking at the object...
    41.     if(!renderer.isVisible)
    42.     {
    43.     move = true;
    44.     }
    45.  
    46.     //If you are not looking at the object...
    47.     if(move)
    48.     {
    49.     //Make him look at the target
    50.     transform.LookAt(target);
    51.     //Always follow the target
    52.     pos.position += pos.forward * speed * Time.deltaTime;
    53.     }
    54.    
    55.     //If he is 3 units away from something, move right (Works if you are not looking at the object)
    56.     if (Physics.Raycast (transform.position, fwd, rayLength)  move)
    57.     {
    58.     Debug.Log("Something ahead, moving");
    59.     transform.Translate(Vector3.right * 3 * Time.deltaTime);
    60.     }
    61.  
    62. }
    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

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    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

    Joined:
    Jul 13, 2005
    Posts:
    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

    Joined:
    Jan 31, 2013
    Posts:
    8
    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

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    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.
     
  6. GeneralZAPP

    GeneralZAPP

    Joined:
    Feb 7, 2018
    Posts:
    2
    Can you make this in C#? Unity doesn't support Java anymore.:(
     
  7. GeneralZAPP

    GeneralZAPP

    Joined:
    Feb 7, 2018
    Posts:
    2
    humanoid. as in a human, but animal XD
     
  8. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    4.5 years.

    Also, I can't see how your comment relates to my answer at all.