Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-2
Question by jazza · Aug 04, 2012 at 11:04 AM · gameobjectaudiocustom

How to make a Slender man follow character script

hi guys i was just wondering if anybody new how to make a script so that the 'slenderman' teleports to positions near the player, and gets closer and closer, sorry for the big ask but could anyone help me out?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DESTRUKTORR · Aug 06, 2012 at 04:28 PM 4
Share

This is a little bit too much to be asking, I think. If you want to grow, as a programmer, you need to learn some basic problem solving, and try something on your own, first.

Just take a step back and try to figure out what you need to do, overall, then come back and ask questions if your code isn't working right. Good luck!

avatar image jazza · Aug 08, 2012 at 01:20 PM 0
Share

kay, thanks!

avatar image babyjay521 · Feb 11, 2013 at 02:59 AM 1
Share

The basic idea is getting the player's position, and changing the slenderman's position in relation to it. Also, you could use RayCasts to find trees and other items that the slenderman could hide behind, and position him so he is there, etc. But like DESTRU$$anonymous$$TORR said, you will really grow as a programmer if you take on this project by yourself. Trust me, it is much more satisfying to see your own program work than to copy and paste someone else's into your game. Also, you will have a better understanding of the program, and you'll be able to make it to best fit you needs. Hope everything works out well for you! EDIT: Just realized how old this was, sorry to bring it back up haha.

avatar image Unitraxx · Apr 04, 2013 at 12:31 AM 0
Share

I actually can't believe it got -6, it's a well-formed question. Ok maybe not a good question for on UAnswers but there's some real rubbish out there that doesn't even get -1.

6 Replies

· Add your reply
  • Sort: 
avatar image
16
Best Answer

Answer by AlucardJay · Oct 21, 2012 at 06:40 AM

This Answer is now CLOSED

Attention Slender Script Shoppers, this question will be closing in 2 minutes.

All future questions about my scripts will only be answered on the new forum page.

Here is the link you are looking for

Unity Forum : http://forum.unity3d.com/threads/172415-Slender-Guide-by-alucardj

I shall not be responding to any more posts here or any other question on Unity Answers either. All future traffic to my 'Slender' Guide is going to be solely through the forum page. Any questions that appear on Unity Answers will be closed and redirected to the forum page.

If you post a new question on Unity Answers with my scripts, I shall bring the hammer down !

While this may seem a little unfair, it is actually a good thing for all of your benefit. Every comment, change and update will appear there, for everyone to read and contribute to. No more searching through different questions just to get different parts of functionality, but everything you could need for starting your own horror survival game will be in one place. Doesn't that sound convenient ?!

See You there =]


Slender Guide Version 2

While I have finished writing the code, I don't have time to write a full guide explaining the steps taken and what I have coded in. I am changing the code in the below guide so people can still make their own rather than just using my package, and I really hope people write their own instead of just using my package.

Slender Guide Version 2 (I can only upload 5MB, so the project is very basic, but working!) : http://www.alucardj.net16.net/unityanswers/SlenderGuideV2-scene0.unitypackage

Fixed problems from Version 1 :

picking up papers in the editor - there were some issues with using LockCursor while running in the editor, hopefully these have been compensated for, recommend use the E key to pick up papers while running in the editor (but mouse still works). some movement issues - I had no problem, but it was brought up so I have tweaked the movement script.

New features :

The more papers picked up, the Man follows closer. Audio : when picking up paper, when the Man is first sighted, running and walking footsteps with adjustable audio gap between steps. Custom mesh with fading alpha fullscreen static effect.

And don't forget the awesome original flickering flashlight!

Here is the video link for the obstacle avoidance raycast : http://vimeo.com/9304844

Comments and feedback are welcome, as long as you have something more to say than just it doesn't work. The package proves it does. And please don't ask new questions, post comments here. If this keeps going or more people have requests, I might have to start a Unity Forum page.

Enjoy =]


How to make a 'Slender' game by Jay Kay (alucardj)

1- Create the terrain, and add a first person controller

there are many tutorials on both these topics, here are some quick links :

video : http://cgcookie.com/unity/2011/12/05/introduction-to-character-controllers/

written : http://wiki.unity3d.com/index.php?title=Terrain_tutorial

Some assets to help you out :

http://unity3d.com/support/resources/assets/terrain-assets

http://u3d.as/content/stormwater/heightfield-pack/2Q4

http://unity3d.com/support/resources/unity-extensions/terrain-toolkit

Also find some buildings (old shed, abandoned shack, etc) and anything you want to help the player use as 'landmarks' while searching around the terrain.

When you add a First Person Character Controller, Change the name of First Person Controller to Player.

2- Set the Ambience and Add a Flashlight

Here I am assuming you have created a terrain, added trees grass and buildings, and dropped in a first person character controller. Hopefully you have also pressed play and walked around the world you have created.

To give the scene a more 'spooky' feel, set the render settings.

In Unity, navigate to Edit > Render Settings

Enable (tick) the box that says Fog.

Click the Fog Colour box, set the ambient light to 29 on each of the RGB sliders. You can see the change in the scene, pick a colour that is dark but not pitch-black.

Click the Ambient Light Colour box, set the ambient light to 51 on each of the RGB sliders. You can see the change in the scene. Again, pick a colour that is dark but not pitch-black.

For a skybox I used the Moonshine skybox from the Standard Assets. (Assets > Import Package > Skyboxes). Drop Moonshine Skybox into Skybox Material (while in the Render Settings).

Now for the flashlight. Create a SpotLight, make it a child of the camera (so wherever the camera looks, the spotlight points). Set its Transform to X = 0; Y = 0.467; Z = 0; leave Rotations at 0, Scale at 1.

My settings for the spotlight are :

Range = 25; Spot Angle = 71.5870; Color I made very slightly yellow; Intensity = 1.85;

Now when you press play, you should be walking around your dark scene with a torchlight effect in front of where you look.

Advancing : I helped someone with a flickering flashlight, and have adapted that script to have the following behaviour. 1- light works for 1-2 minutes. 2- Light starts to flicker. 3- press F to reset light (light flashes twice as if being tapped/shaken) then light works again for another 1-2 minutes. I think it works well to add suspense (the flashlight suddenly flickers, and you have to reset it) . The link is : http://answers.unity3d.com/questions/316189/i-want-to-turn-my-flashlight-on-and-off-while-stil.html#answer-316302

3- How to Pick Up Papers

This one gets asked alot, and the usual response is a trigger-collider setup. For this tutorial, I am going to use a raycast method.

First create some papers. This part is easy =] Create a cube, scale it to X = 0.6; Y = 0.9; Z = 0.01;

Name it Paper. Now Duplicate it 7 times, so you have 8 Paper cubes total.

There are some images that can be found on page 5 of this thread : http://forum.unity3d.com/threads/134862-Slender-Man-Design-Outline

Create a material for each Paper, then apply them to the cubes. You can place these where you want around the scene, just make sure they are set at a realistic height, and preferably so they can only seen from one side (nailed to a thick tree, on the side of a shed).

Now to make it so these papers can be collected.

Create a new script, call it CollectPapers. Attach it to the Player. Here is the code :

  function Start()
  {
       Go TO THE FORUM PAGE !
  }


NOTE : in the Start function, there is the line Screen.lockCursor = true; this is to hide the cursor and lock it to the center of the screen. This can have some silly effects when you run in the editor and then click the mouse, but in a build you notice it works as expected. (this script is adapted from my answer here : http://answers.unity3d.com/questions/239927/Collecting-Papers-and-Keeping-Track-of-how-many-collected--need-help.html)

So, when the left mouse button is released, a ray is cast for a certain distance. If the player is close enough to something named Paper, and the ray hits Paper, then the count is increased and the Paper is destroyed.

At this stage you should be walking around your 'spooky' scene, collecting papers with the amount collected displayed at the top.

Advancing : I found this link for when the paper is found, first displaying the paper full-screen, then destroying the paper. I think that effect would be cool but havn't looked into it yet. The link is : http://answers.unity3d.com/questions/15438/trying-to-pick-up-and-see-paper-pop-up-gui-window.html

4- How to Have an Enemy Follow the Player at a Distance

If you were observant, you would have noticed a model where you got the images for the papers! You can use this, but as the 'man' always looks at the player, a 2D image can be used. Search for an image you want to use (), then make a material for that image. (http://forums.d2jsp.org/topic.php?t=64345908&f=202, http://www.zerochan.net/1271218, etc)

Create a Cube, name it Enemy, scale it to X = 1; Y = 2; Z = 0.1;

Remove or replace the Box Collider with a Capsule Collider ( Component > Physics > Capsule Collider ). My settings for the Capsule Collider are Center = 0 for XYZ, Radius = 0.5, Height = 1, Direction = Y-Axis.

Now also attach a Rigidbody Component ( Component > Physics > Rigidbody ). My settings for the Rigidbody are Mass = 1; Use Gravity = true.

Now for the script, create and call it EnemyScript. I have seen many answers use the Render.isVisible method. For this I am using a Dot.Product method. First there is a check if in a Dot.Product greater than 0.8, then check if within the maximum viewable distance, then check if there is a direct line-of-sight to the player (i.e. not occluded/behind a tree or building). Here is the code :

  function Start()
  {
       Go TO THE FORUM PAGE !
  }


5- Play and Test your Game =]

If all has gone well, you now have your very own Slender game !

This is just the start, try adding many more things :

Add Sounds !! Batteries to pick up for the Flashlight when it runs out of charge. Full screen display of the page when collected. A Game Over screen and a way to restart the game.

Hope you have found this useful and helpful =]

Comment
Add comment · Show 43 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ProShooterXx1 · Oct 21, 2012 at 01:35 PM 0
Share

Ths is very glitchy man... ive done everything what you did. 1. I dont need 100 health. (thats not a glitch but im just saying ... i dont need health and can you tell me how to remove the health? because i just want the enemy to kill me straight away when its close to me... also can you tell me how to make the enemy move a little bit faster when i collect for example... 5th page?) thanks alot. 2. When i attached the script to player, the enemy wont move, it basically stands in 1 place and its not even looking at me. 3. Do you know any good websites for scary models? 4. Can you tell me how to make a model you dont have to go to the details but just how to create a model that has arms and legs and head also when i finish my model... then how do i attach an image to it? because i can make one myself in program called "paint" I am really sorry for my English... i hope you'll understand! :)

avatar image AlucardJay · Oct 21, 2012 at 02:53 PM 1
Share

This is not the type of response I was hoping for after spending a weekend making this.

Please Explain : what do you mean, and in what way is this 'glitchy' ?

This was written to answer 2 of the most commonly asked questions for Slender : How to Pick Up Papers and How to Have an Enemy Follow the Player at a Distance. I wrote the guide at the same time as I made the project from scratch,

And just reeling off a list of questions is not going to help you learn how to code. I am not going to write your game for you. In fact, this is the only guide I have seen for this apart from the guide I link for the images, so don't you consider that to be helpful enough.

Anyway, here's a quick reply to all your questions :

1- the health is there as an example of how you can use being looked at with time. this can be used for the screen effect i have seen of slowly fading to a static image (an image of static noise).

2- What gameObject did you attach the EnemyScript to? and did you name everything as instructed? Perhaps you better check all the gameObjects in the scene to the descriptions in the guide again.

3- http://answers.unity3d.com/questions/16650/game-asset-website-list-free-and-paid-textures-mod.html . $$anonymous$$odels are hard to find for free, but Blender is free if you want to try making your own, and there are lots of guides for using blender. I personally have just found this 'site, and it has been most useful : http://thefree3dmodels.com/

4- As in question 3, to model yourself you need a program like maya or cheetah, Blender and Wings3D are free. What you are describing with painting a model is called UV $$anonymous$$apping. Again this is a very big subject, with many tutorials out there for every modelling program. Just watch some video's to learn the process : http://cgcookie.com/blender/2011/01/21/intro_uvmapping/

5- oh, there wasn't a 5 ? wow ....

avatar image AlucardJay · Oct 21, 2012 at 02:55 PM 2
Share

If you want to know something, a search engine (google) is your friend. Here are all the links I kept that I thought were useful in relation to Slender :

http://answers.unity3d.com/questions/287355/slender-like-game.html

http://answers.unity3d.com/questions/296068/how-to-make-a-slender-man-follow-character-script.html

http://answers.unity3d.com/questions/319733/how-to-make-enemy-kill-you-if-starring-at-it.html

http://forum.unity3d.com/threads/134862-Slender-$$anonymous$$an-Design-Outline

http://www.parsecproductions.net/slendermangame.txt

http://forum.unity3d.com/threads/141488-Slender-Beta-0.9

http://forum.unity3d.com/threads/138399-Slender-$$anonymous$$an-WIP

It's up to you to find the useful information among that. Read.

Break it down to one simple thing. Work out how to find if one object can "see" another. Once you do that, you can make it do anything you like with that as a trigger. And you can do it both for the player and the 'man' .

http://answers.unity3d.com/questions/239927/Collecting-Papers-and-$$anonymous$$eeping-Track-of-how-many-collected--need-help.html

http://answers.unity3d.com/questions/323129/if-anyones-looking-for-a-flashlight-script-with-a.html

http://answers.unity3d.com/questions/316189/i-want-to-turn-my-flashlight-on-and-off-while-stil.html

http://www.youtube.com/watch?v=nmvCaqNGEFU&feature=related

http://answers.unity3d.com/questions/15438/trying-to-pick-up-and-see-paper-pop-up-gui-window.html

http://answers.unity3d.com/questions/321749/how-do-you-pick-up-pages-like-in-slender.html

http://cgcookie.com/unity/2011/12/05/introduction-to-character-controllers/

http://unity3d.com/support/resources/assets/terrain-assets

http://unity3d.com/support/resources/unity-extensions/terrain-toolkit

And maybe next time, don't just write an open-ended unexplained comment like this is glitchy , that really made me think 'why did I even bother to write and post this ....'

avatar image corriedotdev · Oct 21, 2012 at 03:20 PM 1
Share

i would just like to say thankyou very much for making this for the newbies to unity. Im getting used to unity and the paper collecting part really helped me out, my code was a bit off :L Thanks again mate really nice thing you did there!

cheerssss!

avatar image AlucardJay · Feb 18, 2013 at 03:09 AM 2
Share

Hey Ricky, sorry for the very late reply. I never put teleporting into this but am sure it wouldn't be difficult to add.

First, add this line in the Start function to the enemy script :

 InvokeRepeating( "TeleportEnemy", 30, 10 );

Then add this function to the enemy script :

 function TeleportEnemy() 
 {
     // $$anonymous$$ovement : check if out-of-view, then move
     CheckIfOffScreen();
     
     // if is Off Screen, check for Teleport
     if ( isOffScreen )
     {
         // Check the Follow Distance
         CheckDistance();
         
         // if not too close, Teleport
         if ( !isInRange )
         {
             // deter$$anonymous$$e a position to teleport to
             var teleportDistance : float = 50.0; // teleport 50 units to the right of the player (thePlayer.right)
             var newPos : Vector3 = thePlayer.position + ( thePlayer.right * teleportDistance );
             newPos.y = 1000.0;
             
             // raycast to that position
             var hit : RaycastHit;
             
             if ( Physics.Raycast( newPos, -Vector3.up, hit, 1000.0 ) )
             {
                 // check if it hit the terrain
                 if ( hit.collider.gameObject.name == "Terrain" )
                 {
                     // move the enemy to the new position (add a little to the y so it doesn't fall through)
                     theEnemy.position = hit.point + ( Vector3.up * 0.5 );
                     theEnemy.LookAt( thePlayer );
                 }
             }
         }
     }
 }
Show more comments
avatar image
1

Answer by soulblade · Sep 29, 2012 at 02:18 AM

here's my script for making him follow:

 var target : Transform; //the enemy's target
 var moveSpeed = 3; //move speed
 var stopSpeed = 0;
 var rotationSpeed = 3; //speed of turning
 
 var myTransform : Transform; //current transform data of this enemy
 
 function Awake()
 {
     myTransform = transform; //cache transform data for easy access/preformance
 }
 
 function Start()
 {
      target = GameObject.FindWithTag("Player").transform; //target the player
 
 }
 
 function Update () {
 
     var Speed = moveSpeed;
     
     if (renderer.isVisible)
     {
     myTransform.position += myTransform.forward * stopSpeed * Time.deltaTime;
     }
     
     if(!renderer.isVisible)
     {
     myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
     }
     //rotate to look at the player
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
 
 
 
 }

just attach this to slender man and he will follow, hope this helps. :D

Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 10gollem10 · Sep 29, 2012 at 04:32 PM 0
Share

it says: $$anonymous$$issingComponentException: There is no 'Renderer' attached to the "zombie_lowres" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "zombie_lowres". Or your script needs to check if the component is attached before using it.

(I am using in my case "zombie lowres")

avatar image Daten · Sep 29, 2012 at 05:14 PM 1
Share

I really thing you need to learn how to use unity before you continue, There are hundreds if not thousands of tutorials, and the error you have is the most basic error of all!

avatar image 10gollem10 · Sep 30, 2012 at 12:20 PM 0
Share

Oh, thanks. I admit I am very new(I downloaded Unity 2 days ago) I have been looking for tutorials everywhere.

avatar image AlucardJay · Sep 30, 2012 at 02:30 PM 2
Share

Here is a list of tutorials to get you going :

Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/essential-skills/

Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/beginner/

this is the YouTube link for the above as one playlist : http://www.youtube.com/watch?v=-oXYHNSmTxg&list=PL27B696FB515608D2&feature=plcp

the Unity Wiki : http://wiki.unity3d.com/index.php/Tutorials

A list of resources : http://answers.unity3d.com/questions/12321/how-can-i-start-learning-unity-fast-list-of-tutori.html

avatar image 10gollem10 · Oct 03, 2012 at 02:30 PM 0
Share

None of the tutorials are helpful, since it is the most basic error of all is there any way you can explain it?

Show more comments
avatar image
-1

Answer by SiLen7 · Feb 10, 2013 at 07:36 PM

I cant pick up the papers. What is wrong? i made all from your tutorial

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Feb 11, 2013 at 02:48 AM 0
Share

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

Here at Unity Answers, Answer means Solution, not Response.

avatar image cashomalo · Feb 14, 2013 at 08:14 AM 0
Share

Hello @alucardj , can you reupload the package of 5mb please?? The link is dead :( . Thank you

avatar image AlucardJay · Feb 15, 2013 at 01:18 AM 1
Share

As stated above (somewhere in all those comments), I have now removed the packages for my guide. Reasons : no thanks except from 2 people total and 5 votes over 2 answers; when specifically stating don't ask new questions but post problems on those questions, there have been at least 50 questions all using my scripts, all by people that don't understand and just want their game written for them. Looking at your karma rating, I am assu$$anonymous$$g you are one of those, sorry. If you do the guide, everything is there to get the project working yourself. This page has been viewed over 14000 times and the answer only has 9 votes?! I am not writing a game to give away to everyone, just trying to show how to use a Raycast and a Dot Product.

avatar image cashomalo · Feb 15, 2013 at 09:45 AM 0
Share

@alucardj No I was google looking for a tutorial and I saw this post. I never saw it before yesyerday. No get mad bro I jus ask you with education , why you give me an answer like that.

Im sorry if a question offend you.

I dont ask you for a problem , I say that the link is dead, so I did not know that no one thanks you .

There are 14000 and can be a 1000000 millions and million you know why No one Thanks??? Because inity forum No required an account to see and read posts.

About $$anonymous$$AR$$anonymous$$A: look at my post ! I just have one question

avatar image AlucardJay · Feb 15, 2013 at 12:36 PM 0
Share

Just trying to explain why I removed the packages, and why you got that answer on your question. But to try and put a positive spin on things : it looks like you are interested in making this kind of game for months, so again I advise please do my guide. For learning, I have posted many many links for this type of game and some general tutorials, there is a great amount of learning material linked on this page. And I did write this massive answer to help people, so how about give it a go, report back how you went, prove my time writing all that wasn't wasted, and you want to learn rather than just download and use some pre-made package. I do wish you well and hope you master Unity, the world needs to see ideas from everybody.

Show more comments
avatar image
-1

Answer by DavidRoad · Feb 04 at 02:30 AM

so use this c# code

 using UnityEngine;
 using System.Collections;
 
 public class Enemy : MonoBehaviour {
         public float deathDistance = 0.5f;
         public float distanceAway;
         public Transform thisObject;
         public Transform target;
         private NavMeshAgent navComponent;
         
         void Start() 
         {
             target = GameObject.FindGameObjectWithTag("Player").transform;
             navComponent = this.gameObject.GetComponent<NavMeshAgent>();
         }
         
         void Update() 
     {
             
             float dist = Vector3.Distance(target.position, transform.position);
             
             if(target)
             {
                 navComponent.SetDestination(target.position);
             }
 
             else
             {
                 if(target = null)
                 {
                     target = this.gameObject.GetComponent<Transform>();
                 }
                 else
                 {
                     target = GameObject.FindGameObjectWithTag("Player").transform;
                 }
             }
             if (dist <= deathDistance)
             {
                 //KILL PLAYER
             }
         }
     }


then use this javascript code

 #pragma strict
 
 function Start () {
 
 }
 
 function OnTriggerEnter() {
     Application.LoadLevel("YOUR DEATH SCENE");
 }


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daten · Feb 04 at 03:19 PM 0
Share

Jeezus dude, way to necro an almost decade old thread LMAO

avatar image DavidRoad Daten · Feb 07 at 03:25 PM 0
Share

Yeah I Added This Like Decades Ago But I Accidentally Removed It So I Remade It So It May Not Work Now

avatar image
0

Answer by GameMakerJake · Aug 22, 2012 at 09:27 PM

//target to follow var target : Transform;

//Checks his position, used to follow the target var pos : Transform;

//Ray variables (Length... etc.) var rayLength : float = 3;

//Movement, speed etc. var speed : float = 2;

//You can move if he is not being looked at var move : boolean = false;

//I had problems with my model sinking into the floor, adjust this variable if you need it, or remove it function FixedUpdate() { transform.position.y = 2; }

function Update() { //Setting up Raycast variables for simple object avoidance var fwd = transform.TransformDirection (Vector3.forward); var hit : RaycastHit;

     //If you are looking at the object...
     if (renderer.isVisible)
     {
     move = false;
     }
    
     //If you are NOT looking at the object...
     if(!renderer.isVisible)
     {
     move = true;
     }
 
     //If you are not looking at the object...
     if(move)
     {
     //Make him look at the target
     transform.LookAt(target);
     //Always follow the target
     pos.position += pos.forward * speed * Time.deltaTime;
     }
    
     //If he is 3 units away from something, move right (Works if you are not looking at the object)
     if (Physics.Raycast (transform.position, fwd, rayLength) && move)
     {
     Debug.Log("Something ahead, moving");
     transform.Translate(Vector3.right * 3 * Time.deltaTime);
     }
 

}

Idk if that's what you're looking for?

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hecike3 · Aug 24, 2012 at 03:38 PM 0
Share

Thanks alot ! <3 but i have some error so please tell me how i use it .. PLS..

avatar image Mander · Aug 24, 2012 at 03:47 PM 0
Share

what errors?

avatar image hecike3 · Aug 24, 2012 at 03:49 PM 0
Share

parsing error at line 47,5

avatar image Ruffy789 · Aug 26, 2012 at 11:37 AM 0
Share

I got it to work by adding a box collision and using gravity. (Only works if he floats not if he sinks.)

avatar image blackpantherxx · Sep 17, 2012 at 02:33 PM 0
Share

Assets/Slender.cs(1,6): error CS8025: Parsing error

error in : if(renderer.isVisible (the first line)

Show more comments
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Slender like game 3 Answers

GameObject reacts to audio source 1 Answer

Music works but not when accessed by another script in JavaScript 1 Answer

Get acess and switch to many audio source in a single Object HELP!! 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges