a slenderman that moves faster with more pages

hello, ive been looking around for the kind of help above.

i have been tinkering with scripts of a working slenderman, and game concepts. the game works by itself, but i have been trying countless times to change the script so the more pages i collect, the faster slendy gets. so far, i keep failing.

i have experience with javascript, but this is cannot figure out. here is the paper collection script,

#pragma strict
@script RequireComponent( AudioSource )
 
var papers : int = 0;
var papersToWin : int = 8;
var distanceToPaper : float = 2.5;
 
public var paperPickup : AudioClip;
 
var theEnemy : EnemyScript;
 
 
 
 
function Start() 
{
    Screen.lockCursor = true;
 
    // find and store a reference to the enemy script (to reduce distance after each paper is collected)
    if ( theEnemy == null )
    {
       theEnemy = GameObject.Find( "Enemy" ).GetComponent( EnemyScript );
    }
}
 
 
function Update() 
{ 
    //if ( Input.GetMouseButtonUp(0) ) // use E in editor as LockCursor breaks with left mouseclick
    if ( Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.E) ) 
    {
        //var ray = Camera.main.ScreenPointToRay( Input.mousePosition ); // always cast ray from center of screen
        var ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 ) );
        var hit : RaycastHit;
        if ( Physics.Raycast( ray, hit, distanceToPaper ) )
        {
            //if ( hit.collider.gameObject.tag == "Paper" )
            if ( hit.collider.gameObject.name == "Paper" )
            {
                papers += 1;
                //Debug.Log( "A paper was picked up. Total papers = " + papers );
 
                audio.PlayClipAtPoint( paperPickup, transform.position ); 
 
                Destroy( hit.collider.gameObject );
 
                // make enemy follow closer
                theEnemy.ReduceDistance();
            }
        }
    }
}
 
 
function OnGUI()
{
    if ( papers < papersToWin )
    {
       GUI.Box( Rect( (Screen.width * 0.5) - 60, 10, 120, 25 ), "" + papers.ToString() + "Collected" );
    }
    else
    {
       GUI.Box( Rect( (Screen.width/2)-100, 10, 200, 35 ), "All Items Collected!" );
        Application.LoadLevel( "sceneWin" );
    }
}

and this is the slendy script.

#pragma strict
@script RequireComponent( AudioSource )
 
public var thePlayer : Transform;
private var theEnemy : Transform;
 
public var speed : float = 5.0;
 
var isOffScreen : boolean = false;
public var offscreenDotRange : float = 0.7;
 
var isVisible : boolean = false;
public var visibleDotRange : float = 0.8; // ** between 0.75 and 0.85 (originally 0.8172719) 
 
var isInRange : boolean = false;
 
public var followDistance : float = 24.0;
public var maxVisibleDistance : float = 25.0;
 
public var reduceDistAmt : float = 3.1;
 
private var sqrDist : float = 0.0;
 
public var health : float = 100.0;
public var damage : float = 20.0;
 
public var enemySightedSFX : AudioClip;
 
private var hasPlayedSeenSound : boolean = false;
 
private var colDist : float = 5.0; // raycast distance in front of enemy when checking for obstacles
 
 
function Start() 
{
    if ( thePlayer == null )
    {
       thePlayer = GameObject.Find( "Player" ).transform;
    }
 
    theEnemy = transform;
}
 
function Update() 
{
    // Movement : check if out-of-view, then move
    CheckIfOffScreen();
 
    // if is Off Screen, move
    if ( isOffScreen )
    {
       MoveEnemy();
 
       // restore health
       RestoreHealth();
    }
    else
    {
       // check if Player is seen
       CheckIfVisible();
 
       if ( isVisible )
       {
         // deduct health
         DeductHealth();
 
         // stop moving
         StopEnemy();
 
         // play sound only when the Man is first sighted
         if ( !hasPlayedSeenSound )
         {
          audio.PlayClipAtPoint( enemySightedSFX, thePlayer.position ); 
         }
         hasPlayedSeenSound = true; // sound has now played
       }
       else
       {
         // check max range
         CheckMaxVisibleRange();
 
         // if far away then move, else stop
         if ( !isInRange )
         {
          MoveEnemy();
         }
         else
         {
          StopEnemy();
         }
 
         // reset hasPlayedSeenSound for next time isVisible first occurs
         hasPlayedSeenSound = false;
       }
    }
 
}
 
 
function DeductHealth() 
{
    // deduct health
    health -= damage * Time.deltaTime;
 
    // check if no health left
    if ( health <= 0.0 )
    {
       health = 0.0;
       Debug.Log( "YOU ARE OUT OF HEALTH !" );
 
       // Restart game here!
        Application.LoadLevel( "sceneLose" );
    }
}
 
 
function RestoreHealth() 
{
    // deduct health
    health += 3 * Time.deltaTime;
 
    // check if no health left
    if ( health >= 100.0 )
    {
       health = 100.0;
       //Debug.Log( "HEALTH is FULL" );
    }
}
 
 
function CheckIfOffScreen() 
{
    var fwd : Vector3 = thePlayer.forward.normalized;
    var other : Vector3 = (theEnemy.position - thePlayer.position).normalized;
 
    var theProduct : float = Vector3.Dot( fwd, other );
 
    if ( theProduct < offscreenDotRange )
    {
       isOffScreen = true;
    }
    else
    {
       isOffScreen = false;
    }
}
 
 
function MoveEnemy() 
{
    // Check the Follow Distance
    CheckDistance();
 
    // if not too close, move
    if ( !isInRange )
    {
       rigidbody.velocity = Vector3( 0, rigidbody.velocity.y, 0 ); // maintain gravity
 
       // --
       // Old Movement
       //transform.LookAt( thePlayer );   
       //transform.position += transform.forward * speed * Time.deltaTime;
       // --
 
       // New Movement - with obstacle avoidance
       var dir : Vector3 = ( thePlayer.position - theEnemy.position ).normalized;
       var hit : RaycastHit;
 
       if ( Physics.Raycast( theEnemy.position, theEnemy.forward, hit, colDist ) )
       {
         //Debug.Log( " obstacle ray hit " + hit.collider.gameObject.name );
         if ( hit.collider.gameObject.name != "Player" && hit.collider.gameObject.name != "Terrain" )
         {         
          dir += hit.normal * 20;
         }
       }
 
       var rot : Quaternion = Quaternion.LookRotation( dir );
 
       theEnemy.rotation = Quaternion.Slerp( theEnemy.rotation, rot, Time.deltaTime );
       theEnemy.position += theEnemy.forward * speed * Time.deltaTime;
 
       // --
    }
    else
    {
       StopEnemy();
    }
}
 
 
function StopEnemy() 
{
    transform.LookAt( thePlayer );
 
    rigidbody.velocity = Vector3.zero;
}
 
 
function CheckIfVisible() 
{
    var fwd : Vector3 = thePlayer.forward.normalized;
    var other : Vector3 = ( theEnemy.position - thePlayer.position ).normalized;
 
    var theProduct : float = Vector3.Dot( fwd, other );
 
    if ( theProduct > visibleDotRange )
    {
       // Check the Max Distance
       CheckMaxVisibleRange();
 
       if ( isInRange )
       {
         // Linecast to check for occlusion
         var hit : RaycastHit;
 
         if ( Physics.Linecast( theEnemy.position + (Vector3.up * 1.75) + theEnemy.forward, thePlayer.position, hit ) )
         {
          Debug.Log( "Enemy sees " + hit.collider.gameObject.name );
 
          if ( hit.collider.gameObject.name == "Player" )
          {
              isVisible = true;
          }
         }
       }
       else
       {
         isVisible = false;
       }
    }
    else
    {
       isVisible = false;
    }
}
 
 
function CheckDistance() 
{
    var sqrDist : float = (theEnemy.position - thePlayer.position).sqrMagnitude;
    var sqrFollowDist : float = followDistance * followDistance;
 
    if ( sqrDist < sqrFollowDist )
    {
       isInRange = true;
    }
    else
    {
       isInRange = false;
    }  
}
 
 
function ReduceDistance() 
{
    followDistance -= reduceDistAmt;
}
 
 
function CheckMaxVisibleRange() 
{
    var sqrDist : float = (theEnemy.position - thePlayer.position).sqrMagnitude;
    var sqrMaxDist : float = maxVisibleDistance * maxVisibleDistance;
 
    if ( sqrDist < sqrMaxDist )
    {
       isInRange = true;
    }
    else
    {
       isInRange = false;
    }  
}
 
 
function OnGUI()
{
    GUI.Box( Rect( (Screen.width * 0.5) - 60, Screen.height - 35, 120, 25 ), "Health : " + parseInt( health ).ToString() );
}

im not particularily asking anyone to make the script work for me, (it’d be nice though) but advice on how to make it so, or a tutorial link.

or you can take the script listed. credit to alucardj

any help is appreciated

This is actually very very easy =]

Although I specifically asked that all questions related to my scripts be asked on the page they were found, I shall answer this here and now.

I see you have made the V2 edit where the distance is reduced every paper collected, and this is Exactly where to tap in to add the functionality you are asking for.

Ok, let’s look at the theory :

In CollectPapers, there is a command that calls a function on the enemy script :

if ( hit.collider.gameObject.name == "Paper" )
{
    papers += 1;
    //Debug.Log( "A paper was picked up. Total papers = " + papers );
     
    audio.PlayClipAtPoint( paperPickup, transform.position );
     
    Destroy( hit.collider.gameObject );
    
    // make enemy follow closer
    theEnemy.ReduceDistance();
}

See it … theEnemy.ReduceDistance();

This is activated every time a paper is collected. It reduces the follow distance. Here is that function on the EnemyScript :

function ReduceDistance()
{
    followDistance -= reduceDistAmt;
}

And there’s your answer, put your speed modifying code right there ! Let’s modify this portion. First add a new variable, then modify the function to :

public var speedIncrement : float = 1.25;

function ReduceDistance()
{
    followDistance -= reduceDistAmt;
    
    speed += speedIncrement;
}

Wham bam, done and done =]

Addition :* I see you missed the edit where for the first paper, the enemy doesn’t follow or teleport. Once the first paper is collected, the hunt begins !

Here is that edit :

1.) My enemy follows me as soon as i spawn and runs at me How do i fix this so he spawns when i collect the first page and how do i make him follow at a distance.

If this was a video series, then the scripts would be totally different. For example the health would actually be on the player where it belongs, it was just easier to do it the way I have to make this written guide much easier to follow. So adding what you ask here is a bit tricky with the current setup.

This needs some changes to both the EnemyScript and CollectPapersScript to add this functionality.

Step 1 : On the EnemyScript, add these variables :

public var startingDistance : float = 2000.0;
private var firstPaperDistance : float = 24.0;

Now in the Start function, add these lines :

firstPaperDistance = followDistance;
followDistance = startingDistance;

Now add this new function :

function SetFirstPaperDistance() 
{
    followDistance = firstPaperDistance;
}

Step 2 : Now on the CollectPapersScript, find this line :

// make enemy follow closer
theEnemy.ReduceDistance();

delete and replace those lines with this :

// make enemy follow closer
if ( papers == 1 )
{
    theEnemy.SetFirstPaperDistance();
}
else
{
    theEnemy.ReduceDistance();
}

As startingDistance is a ridiculously high value, the Enemy thinks it is inRange so doesn’t move until the first paper is collected. When SetFirstPaperDistance() is called, the enemy goes back to a decent hunting distance and works like before. This is tested and working.

If you don’t have the teleporting, just check my last comment on that answer (How to make a Slender man follow character script - Questions & Answers - Unity Discussions), it’s easy to find so I’m not going to copy-paste that portion here.

… you were lucky I saw this before it got closed. Normally I would have chucked a tantrum at you not asking on the post with my answer, but you caught me in a good mood. That and you must be a little psychic, because as I type this, I am uploading the first video (of 7) with me following my own guide, to show all the people that say “this doesn’t work” that in fact it does work ! Here’s the proof :

[8423-slender+video+1+uploading+3.png|8423]

After 9 months I cannot believe that answer is still getting views, and check out how many, nearly 17000 ! wow, just wow. As it is still popular, I am starting with the videos, then moving the whole guide to the forums, where everyone can just find the answers and post on one page , and hopefully help each other as well to make your own epic Horror Survival games. This is a good consideration, so now I have to make another video just to add this ! It looks like I am doomed to keep writing and modifying these scripts. I wouldn’t mind if even 1% of the viewers actually voted my answer up. That would be a cool way of saying thanks.

Anyway, hope this helps, have fun and Happy Coding =]

I do not read the whole script as I’m too lazy to.

In your first script, you have
papers += 1; at line 40, from there you can calculate the speed of the slendy.

Something like this will do:

if ( hit.collider.gameObject.name == "Paper" )
{
   papers += 1;
   
   //Either this 
   slendy.speed = ( //some calculation here );
   //Or this will do
   slendy.CalculateSpeed( papers );

   ...
   ...
}