Search Unity

Slender Guide by alucardj

Discussion in 'Scripting' started by AlucardJay, Mar 2, 2013.

Thread Status:
Not open for further replies.
  1. nownz

    nownz

    Joined:
    Aug 13, 2013
    Posts:
    14
    i try but too hard :/

    i just need to the player" First Person Controller" die ... any way to do it?
     
  2. addy253

    addy253

    Joined:
    Jul 31, 2013
    Posts:
    5
    Theres links for the scripts on the first page so the hardest part is already done download the newest version of scripts and follow videos there's no other simple way I've hit a lot of errors an set backs within a space of nearly 6-7 weeks I've had to restart my project it's not that I can't do it it's that I'm making mine for android and there's lots of hidden issues and ways to rectify them I had to restart yesterday cuz my terrain was massive and the scenery and foliage took up too much cpu and was more choppy than a butchers, I was flying on a non jumping game so I've cleaned me terrain made the play area smaller I'm now making the models and further models very low polly an see how that goes it's a batch cuz i spent the best part of 2 days correcting and adding finishing touches to the terrain but u live u learn it happens
     
  3. xdandamanx66

    xdandamanx66

    Joined:
    Apr 21, 2013
    Posts:
    5
    hey Alucard, love ur video's and guide and its helped me so much but i have one question. i want my slenderman to stand still when i look at him and when he walks closer to me he wont fiz but if u get the model not done by blender he will stay still and teleport and fiz plz help BTW the slender not done by blender is halfway in the ground
     
    Last edited: Aug 24, 2013
  4. Halo500

    Halo500

    Joined:
    Apr 24, 2013
    Posts:
    37
    Hello Alucardj! How have you been?

    I've been messing around with the mesh colliders (changing any that I can to box colliders) and clipping planes (Camera) to reduce some lag. I came across the "Field of View" on the camera.

    Is there some possible way to have, in the "NPCMovement.js", to add to where when you're looking at Slenderman the script messes with the camera to where the "Field of View" begins to increase, making it look like you're vision is getting distorted and stretched out, adding more effects to make it seem more like you ARE losing your sanity when looking at Slenderman? :)
     
  5. Halo500

    Halo500

    Joined:
    Apr 24, 2013
    Posts:
    37
    I understand what addy is going through. It spent me about 2 months getting the jist of this tutorial and getting adjusted to Unity, then the rest of my Summer Break correcting the game errors I had, learning more scripting, and trying to convert the game into Android. My app is called Slendy on the Google Play store for the past month or 2 now and it's doing great! :D
     
  6. addy253

    addy253

    Joined:
    Jul 31, 2013
    Posts:
    5
    Ive had to halt production of my game, my pc has crapped out on me this morning i either fork out for a new one and get all my models and programs again *which will take forever* and then rebild or i could fork out for repairs which might not work *sigh* aint life grand
     
  7. PrinceOfUnity

    PrinceOfUnity

    Joined:
    Jun 16, 2013
    Posts:
    4
    Please help ;

    Code (csharp):
    1.  
    2. NullReferenceException
    3. CollectPapers.Start () (at C:/Users/win7/Desktop/SlenderGame/Assets/_Scripts/CollectPapers.js:56)
    And ;


    Code (csharp):
    1. NullReferenceException
    2. SceneLoseEffect.Start () (at C:/Users/win7/Desktop/SlenderGame/Assets/_Scripts/SceneLoseEffect.js:63)

    And :D :


    Code (csharp):
    1. No paper Display Object in the Inspector
    2. UnityEngine.Debug:LogWarning(Object)
    3. CollectPapers:Start() (at C:/Users/win7/Desktop/SlenderGame/Assets/_Scripts/CollectPapers.js:55)
    4.  
    And :


    Code (csharp):
    1. no object named player was found
    2. UnityEngine.Debug:Log(Object)
    3. NPCMovement:Start() (at C:/Users/win7/Desktop/SlenderGame/Assets/_Scripts/NPCMovement.js:98)

    And :


    Code (csharp):
    1. [mecanim]: BindSkeleton: cannot find Transform 'Camera'

    And game freezes. :(
     
    Last edited: Oct 4, 2013
  8. Gamer220

    Gamer220

    Joined:
    Oct 13, 2013
    Posts:
    1
    The Scripts Link Do Not Work
     
  9. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    Ok, first of all, awesome tutorial series, I don't care abut making a slender game I was watching the raycasting to avoid obstacles parts, and they really helped!

    But I have a bit of a problem. I went through the 8 pages here to see if anyone asked but I guess not. I've been at this for a good day, and its 5AM, crap...

    Anyway, the raycasting to avoid obstacles works fine if you're avoiding a giant wall but if its something thinner than the NPC, the NPC will run into it and get stuck cause the object will be between the two raycasts on the side. I tried making a third ray that just goes forward but it isn't working well, the NPC just spins around the object the forward ray hits, I don't know how to make the three rays cooperate. Here's the "Moving()" function part of the script if someone can help me. I also I made the rays on the side diagonal for testing to see if its better, and cause I wanted a forward ray too.

    Code (csharp):
    1. function Moving()
    2. {
    3.     //Rotation
    4.     var lookDirection : Vector3 = (target.position - transform.position).normalized;
    5.     var hit : RaycastHit;
    6.    
    7.     var diagonalLeft = transform.TransformDirection(-1, 0, 3);
    8.     var diagonalRight = transform.TransformDirection(1, 0, 3);
    9.    
    10.     var leftRayPos : Vector3 = transform.position - (transform.right * shoulderMultiplier);
    11.     var rightRayPos : Vector3 = transform.position + (transform.right * shoulderMultiplier);
    12.        
    13.     if(Physics.Raycast(leftRayPos, diagonalLeft, hit, rayDistance))
    14.     {
    15.         Debug.DrawLine(leftRayPos, hit.point, Color.red);
    16.         lookDirection += hit.normal * 20;
    17.         Debug.Log("Hitting Left!");
    18.     }
    19.     else if(Physics.Raycast(rightRayPos, diagonalRight, hit, rayDistance))
    20.     {
    21.         Debug.DrawLine(rightRayPos, hit.point, Color.red);
    22.         lookDirection += hit.normal * 20;
    23.         Debug.Log("Hitting Right!");
    24.     }
    25.     else if(Physics.Raycast(transform.position, transform.forward, hit, rayDistance))
    26.     {
    27.         Debug.DrawLine(transform.position, hit.point, Color.red);
    28.         lookDirection += hit.normal * 20;
    29.         Debug.Log("Hitting Forward!");
    30.     }
    31.     else
    32.     {
    33.         Debug.DrawRay(leftRayPos, diagonalLeft * rayDistance/3, Color.yellow);
    34.         Debug.DrawRay(rightRayPos, diagonalRight * rayDistance/3, Color.yellow);
    35.         Debug.DrawRay(transform.position, transform.forward * rayDistance, Color.yellow);
    36.     }
    37.     if(Physics.Raycast(transform.position, -transform.up, hit, rayDistance))
    38.     {
    39.         isGrounded = true;
    40.         Debug.DrawLine(transform.position, hit.point, Color.red);
    41.     }
    42.     else
    43.     {
    44.         isGrounded = false;
    45.         Debug.DrawRay(transform.position, -transform.up * rayDistance, Color.yellow);
    46.     }
    47.    
    48.     var lookRot : Quaternion = Quaternion.LookRotation(lookDirection);
    49.     transform.rotation = Quaternion.Slerp(transform.rotation, lookRot, rotSpeed * Time.deltaTime);
    50.     transform.rotation.x = 0;
    51.     transform.rotation.z = 0;
    52.     //Moving
    53.     //transform.position+= transform.forward * acceleration * Time.deltaTime;
    54.     desiredVelocity = transform.forward * acceleration;
    55.     desiredVelocity.y = rigidbody.velocity.y;
    56. }
     
  10. assil

    assil

    Joined:
    Jan 21, 2014
    Posts:
    3
    Hi Alucardj, thank you for the tutoriel of the AI. It help me a lot. But i have a problem with it. I just begun to use unity (2 weeks ) and i designed a maze gem where the player is chasing by an enemy. the enemy should follow the player. This work fine but the enemy cross the wall of the maze ( i use cube to design it). I dont know why.

    this is the script that i use.


    #pragma strict
    @script RequireComponent( Rigidbody )

    private var myTransform : Transform; // us as the NPC
    private var myRigidbody : Rigidbody;

    var target : Transform; // the Player


    var moveSpeed : float = 6.0;
    var turnSpeed : float = 2.0;

    private var desiredVelocity : Vector3;

    var isGrounded : boolean = false;

    var rayDistance : float = 5.0;


    enum NPC
    {
    Idle,
    FreeRoam,
    Chasing,
    RunningAway
    }

    var myState : NPC;

    var minimumRange : float = 35.0;
    var maximumRange : float = 35.0;

    private var minimumRangeSqr : float;
    private var maximumRangeSqr : float;

    var isNpcChasing : boolean = true;

    var freeRoamTimer : float = 0.0;
    var freeRoamTimerMax : float = 5.0;
    var freeRoamTimerMaxRange : float = 1.5;
    var freeRoamTimerMaxAdjusted : float = 5.0;

    private var calcDir : Vector3 = Vector3.forward;

    var isSlender : boolean = true;

    var isVisible : boolean = false;

    var offScreenDot : float = 0.8;

    public var enemySightedSound : AudioClip;

    private var hasPlayedSeenSound : boolean = false;

    private var reduceDistanceAmount : float;

    var increaseSpeedAmount : float = 0.5;


    function ReduceDistance()
    {
    minimumRange -= reduceDistanceAmount;
    minimumRangeSqr = minimumRange * minimumRange;

    moveSpeed += increaseSpeedAmount;
    }


    function Start()
    {
    reduceDistanceAmount = ( maximumRange - 4.0 ) / 7.0;

    minimumRangeSqr = minimumRange * minimumRange;
    maximumRangeSqr = maximumRange * maximumRange;

    myTransform = transform;
    myRigidbody = rigidbody;

    myRigidbody.freezeRotation = true;

    freeRoamTimer = 1000.0;

    if ( isSlender )
    {
    InvokeRepeating( "TeleportEnemy", 60.0, 20.0 );


    var targetObject : GameObject = GameObject.Find( "Player" );

    if ( targetObject )
    {
    target = targetObject.transform;

    }
    else
    {
    Debug.Log( "no object named player was found" );
    }
    }
    }


    function TeleportEnemy()
    {
    CheckIfVisible();

    if ( !isVisible )
    {
    var sqrDist : float = ( target.position - myTransform.position ).sqrMagnitude;

    if ( sqrDist > maximumRangeSqr + 25.0 )
    {
    var teleportDistance : float = maximumRange + 15.0; // or originally 5

    // method 1
    //var terrainPosCheck : Vector3 = target.position + ( myTransform.right * teleportDistance ); // happy accident

    // method 2
    var rndDir : int = Random.Range( 0, 2 );

    if ( rndDir == 0 )
    {
    rndDir = -1;
    }

    var terrainPosCheck : Vector3 = target.position + ( rndDir * target.right * teleportDistance );
    // --

    terrainPosCheck.y = 5000.0;

    var hit : RaycastHit;

    if ( Physics.Raycast( terrainPosCheck, -Vector3.up, hit, Mathf.Infinity ) )
    {
    if ( hit.collider.gameObject.name == "Terrain" )
    {
    myTransform.position = hit.point + new Vector3( 0, 0.25, 0 );
    }
    }
    }
    }
    }


    function SlenderDecisions()
    {
    CheckIfVisible();

    var sqrDist : float = ( target.position - myTransform.position ).sqrMagnitude;

    if ( isVisible )
    {
    // check the range
    if ( sqrDist > maximumRangeSqr )
    {
    myState = NPC.Chasing;
    }
    else
    {
    var hit : RaycastHit;

    if ( Physics.Linecast( myTransform.position, target.position, hit ) )
    {
    //Debug.Log( hit.collider.gameObject.name );

    Debug.DrawLine( myTransform.position, target.position, Color.green );

    if ( hit.collider.gameObject.name == target.name )
    {
    myState = NPC.Idle;

    // decrease the health of the player

    if ( !hasPlayedSeenSound )
    {
    audio.PlayClipAtPoint( enemySightedSound, target.position );
    hasPlayedSeenSound = true;
    }

    }
    else
    {
    myState = NPC.Chasing;
    }
    }
    }
    }
    else // is NOT visible
    {
    if ( sqrDist > minimumRangeSqr )
    {
    myState = NPC.Chasing;
    }
    else
    {
    myState = NPC.Idle;
    }

    hasPlayedSeenSound = false;
    }
    }


    function CheckIfVisible()
    {
    var fwd : Vector3 = target.forward;
    var other : Vector3 = ( myTransform.position - target.position ).normalized;

    var dotProduct : float = Vector3.Dot( fwd, other );

    isVisible = false;

    if ( dotProduct > offScreenDot )
    {
    isVisible = true;
    }
    }


    function Update()
    {
    if ( isSlender )
    {
    SlenderDecisions();
    }
    else
    {
    MakeSomeDecisions();
    }



    switch( myState )
    {
    case NPC.Idle :
    // looking directly at player
    //myTransform.LookAt( target );

    // looking towards player but upright
    var targetLookRot : Vector3 = Vector3( target.position.x, myTransform.position.y, target.position.z );
    myTransform.LookAt( targetLookRot );

    // unly use the gravity Y velocity
    desiredVelocity = new Vector3( 0, myRigidbody.velocity.y, 0 );
    break;

    case NPC.FreeRoam :
    freeRoamTimer += Time.deltaTime;

    if ( freeRoamTimer > freeRoamTimerMaxAdjusted )
    {
    freeRoamTimer = 0.0;
    freeRoamTimerMaxAdjusted = freeRoamTimerMax + Random.Range( -freeRoamTimerMaxRange, freeRoamTimerMaxRange );

    calcDir = Random.onUnitSphere;
    calcDir.y = 0.0;
    }

    Moving( calcDir );
    break;

    case NPC.Chasing :
    Moving( (target.position - myTransform.position).normalized );
    break;

    case NPC.RunningAway :
    Moving( (myTransform.position - target.position).normalized );
    break;
    }
    }


    function MakeSomeDecisions()
    {
    var sqrDist : float = ( target.position - myTransform.position ).sqrMagnitude;

    if ( sqrDist > maximumRangeSqr )
    {
    if ( isNpcChasing )
    {
    myState = NPC.Chasing;
    }
    else
    {
    myState = NPC.FreeRoam;
    }
    }
    else if ( sqrDist < minimumRangeSqr )
    {
    if ( isNpcChasing )
    {
    myState = NPC.Idle;
    }
    else
    {
    myState = NPC.RunningAway;
    }
    }
    else
    {
    if ( isNpcChasing )
    {
    myState = NPC.Chasing;
    }
    else
    {
    myState = NPC.RunningAway;
    }
    }
    }


    function Moving( lookDirection : Vector3 )
    {
    // rotation
    //var lookDirection : Vector3 = (target.position - myTransform.position).normalized;

    var hit : RaycastHit;

    var shoulderMultiplier : float = 0.75;

    var leftRayPos : Vector3 = myTransform.position - ( myTransform.right * shoulderMultiplier );
    var rightRayPos : Vector3 = myTransform.position + ( myTransform.right * shoulderMultiplier );

    if ( Physics.Raycast( leftRayPos, myTransform.forward, hit, rayDistance ) )
    {
    if ( hit.collider.gameObject.name != "cube")
    {
    Debug.DrawLine( leftRayPos, hit.point, Color.red );

    lookDirection += hit.normal * 20.0;
    }
    }
    else if ( Physics.Raycast( rightRayPos, myTransform.forward, hit, rayDistance ) )
    {
    if ( hit.collider.gameObject.name != "cube")
    {
    Debug.DrawLine( rightRayPos, hit.point, Color.red );

    lookDirection += hit.normal * 20.0;
    }
    }
    else
    {
    Debug.DrawRay( leftRayPos, myTransform.forward * rayDistance, Color.yellow );
    Debug.DrawRay( rightRayPos, myTransform.forward * rayDistance, Color.yellow );
    }


    //Debug.Log( "velocity = " + myRigidbody.velocity + " : vel mag = " + myRigidbody.velocity.magnitude + " : vel mag sqr = " + myRigidbody.velocity.sqrMagnitude );

    // if myRigidbody.velocity.sqrMagnitude < 1.75 then the NPC is stuck
    if ( myRigidbody.velocity.sqrMagnitude < 1.75 )
    {
    lookDirection += myTransform.right * 20.0;
    }


    var lookRot : Quaternion = Quaternion.LookRotation( lookDirection );

    myTransform.rotation = Quaternion.Slerp( myTransform.rotation, lookRot, turnSpeed * Time.deltaTime );

    // movement
    desiredVelocity = myTransform.forward * moveSpeed;
    desiredVelocity.y = myRigidbody.velocity.y;
    }


    function FixedUpdate()
    {
    if ( isGrounded )
    {
    myRigidbody.velocity = desiredVelocity;
    }
    }


    function OnCollisionEnter( collision : Collision )
    {
    if ( collision.collider.gameObject.name == "cube")
    {
    isGrounded = true;
    }
    }


    function OnCollisionStay( collision : Collision )
    {
    if ( collision.collider.gameObject.name == "cube")
    {
    isGrounded = true;
    }
    }


    function OnCollisionExit( collision : Collision )
    {
    if ( collision.collider.gameObject.name == "cube")
    {
    isGrounded = false;
    }
    }
     
  11. jriddensdale

    jriddensdale

    Joined:
    Dec 29, 2013
    Posts:
    2
    Can you put all your scripts on unity aswers?
     
  12. thingimibob

    thingimibob

    Joined:
    Nov 1, 2013
    Posts:
    39
    thanks it was so helpful
     
  13. MyPix

    MyPix

    Joined:
    Feb 23, 2014
    Posts:
    44
    Hello, i need some help with this script.
    http://prntscr.com/2vgq6i
    http://prntscr.com/2vgqki
    But when my player get next to the "Slender" object, it doesn't loose health.
    DeductHealth function is never called (i tried with debug.log to see if called)

    So. Have you a fix for this ?
     
  14. Rapfan28

    Rapfan28

    Joined:
    Mar 27, 2015
    Posts:
    21
    uh hey sup im new to unity and i just wanted to ask if you could fix a sprint timer for jay's code please ? here's the code incase you don't have it :

    Code (JavaScript):
    1.  
    2. #pragma strict
    3. @script RequireComponent( AudioSource )
    4. @script RequireComponent( CharacterController )
    5. @script RequireComponent( CharacterMotor )
    6.  
    7. var walkSounds : AudioClip[];
    8. var runSounds : AudioClip[];
    9.  
    10. var walkAudioSpeed : float = 0.4;
    11. var runAudioSpeed : float = 0.2;
    12.  
    13. private var walkAudioTimer : float = 0.0;
    14. private var runAudioTimer : float = 0.0;
    15.  
    16. var isWalking : boolean = false;
    17. var isRunning : boolean = false;
    18.  
    19. var walkSpeed: float = 8; // regular speed
    20. var runSpeed: float = 20; // run speed
    21.  
    22. private var chCtrl: CharacterController;
    23. private var chMotor: CharacterMotor;
    24.  
    25. function Start()
    26. {
    27.     chCtrl = GetComponent(CharacterController);
    28.     chMotor = GetComponent(CharacterMotor);
    29. }
    30.  
    31. function Update()
    32. {
    33.     SetSpeed();
    34.    
    35.     if ( chCtrl.isGrounded )
    36.     {
    37.         PlayFootsteps();
    38.     }
    39.     else
    40.     {
    41.         walkAudioTimer = 1000.0;
    42.         runAudioTimer = 1000.0;
    43.     }
    44. }
    45.  
    46. function SetSpeed()
    47. {
    48.     var speed = walkSpeed;
    49.    
    50.     if ( chCtrl.isGrounded && Input.GetKey("left shift") || Input.GetKey("right shift") )
    51.     {
    52.         speed = runSpeed;
    53.     }
    54.    
    55.     chMotor.movement.maxForwardSpeed = speed;
    56. }
    57.  
    58. function PlayFootsteps()
    59. {
    60.     if ( Input.GetAxis( "Horizontal" ) || Input.GetAxis( "Vertical" ) )
    61.     {
    62.         if ( Input.GetKey( "left shift" ) || Input.GetKey( "right shift" ) )
    63.         {
    64.             // Running
    65.             isWalking = false;
    66.             isRunning = true;
    67.         }
    68.         else
    69.         {
    70.             // Walking
    71.             isWalking = true;
    72.             isRunning = false;
    73.         }
    74.     }
    75.     else
    76.     {
    77.         // Stopped
    78.         isWalking = false;
    79.         isRunning = false;
    80.     }
    81.    
    82.     // Play Audio
    83.     if ( isWalking )
    84.     {
    85.         if ( walkAudioTimer > walkAudioSpeed )
    86.         {
    87.             audio.Stop();
    88.             audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
    89.             audio.Play();
    90.             walkAudioTimer = 0.0;
    91.         }
    92.     }
    93.     else if ( isRunning )
    94.     {
    95.         if ( runAudioTimer > runAudioSpeed )
    96.         {
    97.             audio.Stop();
    98.             audio.clip = runSounds[ Random.Range( 0, runSounds.Length ) ];
    99.             audio.Play();
    100.             runAudioTimer = 0.0;
    101.         }
    102.     }
    103.     else
    104.     {
    105.         audio.Stop();
    106.     }
    107.    
    108.     // increment timers
    109.     walkAudioTimer += Time.deltaTime;
    110.     runAudioTimer += Time.deltaTime;
    111. }
     
  15. Rapfan28

    Rapfan28

    Joined:
    Mar 27, 2015
    Posts:
    21
    no wait i fixed it i saw jay fix it himself in a thread
     
  16. t0nin0t

    t0nin0t

    Joined:
    Aug 29, 2014
    Posts:
    1
  17. Rapfan28

    Rapfan28

    Joined:
    Mar 27, 2015
    Posts:
    21
    Guy Farting? Hey dude, I downloaded your game and the thing is that you have to update slendy's ai dude. I mean, whenever I play the school map I noticed that he always comes at me from the left. And why is slender moving? That's really annoying you know
     
  18. unity_5Ym775GeJmT86Q

    unity_5Ym775GeJmT86Q

    Joined:
    Mar 7, 2020
    Posts:
    3
    Can someone give me a slender model please?
    I only don't want the arrival slender model or the eight pages model :|
     
  19. unity_5Ym775GeJmT86Q

    unity_5Ym775GeJmT86Q

    Joined:
    Mar 7, 2020
    Posts:
    3
    Sorry if it's been 1 year, but use this awesome slenderman model made by Superman999 (i'm using it too)
    http://www.mediafire.com/download/wb5rhhpqrxwojyc/slender.zip
    By the way, don't forget to credit him!
    You can just open the .blend file then export the model to an format that unity supports
    ps: i recommend exporting to .fbx or .obj
     
  20. Julydevelopergame

    Julydevelopergame

    Joined:
    Jun 10, 2023
    Posts:
    63
    its everyone gonna use this???
     
  21. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    Please don't necropost.

    Closing this thread from 2013.

    Thanks.
     
    Kurt-Dekker likes this.
Thread Status:
Not open for further replies.