Unity Community


Results 1 to 5 of 5

  1. Posts
    261

    Free 'Weeping Angels' eqsue script

    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:  
    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 by suctioncup; 06-27-2013 at 12:03 AM.


  2. Location
    Sweden
    Posts
    1,408
    You do realize that CC licenses are intended for works of art and are not really that compatible with code.
    My Open Source Projects: UdpKit, IronJS, Free Unity Assets
    Need unity consulting? Contact me over PM or Here


  3. Location
    Chicago
    Posts
    23
    Quote Originally Posted by fholm View Post
    You do realize that CC licenses are intended for works of art and are not really that compatible with code.
    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. 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. Posts
    1,418
    Quote Originally Posted by christianmanners View Post
    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?
    Code:  
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •