Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Cbjfan1 · Jul 22, 2012 at 12:03 AM · freezenpclookhorror

Enemy stop moving when stared at

I started unity, and scripting a month ago and I am trying to make a monster where if you look at him, he doesn't move (similar to SCP Containment breach, and Slender). I currently have a block childed to the camera, and want it so when the collider hits the monsters collider, he freezes. Can anyone start me off on a script? Thanks in advance

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 AlucardJay · Jul 22, 2012 at 12:18 AM 0
Share

I thought there was a similar question to this a while back, and after searching it was yours. http://answers.unity3d.com/questions/273809/need-an-enemy-script-that-makes-him-wander-and-det.html

I find this interesting, as the concept re$$anonymous$$ds me of the statues in Dr Who =]

It sounds like you have thought about it and made start. The idea is ok, having a invisible block that basically lives in the player view. You are soo close, all you need to do is add an OnTriggerEnter or OnCollisionEnter on the monster script to say freeze someone's looking, then OnTriggerExit/OnCollisionExit to say ok no-one's looking so move.

watch this video : http://www.unity3dstudent.com/2010/07/beginner-b13-trigger-collision-detection/

http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html

http://answers.unity3d.com/questions/240136/sliding-door-animation-question.html

EDIT : if you are just starting out, do all the $$anonymous$$i-projects on unity3dstudent (they are about 5 $$anonymous$$utes each) : http://www.unity3dstudent.com/category/modules/beginner/

it's in reverse order, so scroll down and start at Beginner B00 – Adding $$anonymous$$ass / Gravity with Rigidbodies

avatar image Cbjfan1 · Jul 22, 2012 at 01:43 AM 0
Share

I checked out the video, and other links. What would I need to add to make it disable a script temporarily once the trigger cube is over the other collider?

avatar image AlucardJay · Jul 22, 2012 at 01:49 AM 0
Share

You want to disable the movement, yes, but just makes things more complicated for what you want to do (even though disabling the script is possible). Ins$$anonymous$$d, have a boolean on the monster script and check it before the movement, and use OnTriggerEnter and Exit to toggle this boolean. e.g.

 var isSeen : boolean = false;

 function Update() 
 {
     if (!isSeen) // ! means if (isSeen == false)
     {
         $$anonymous$$ove$$anonymous$$onster();
     }
 }

 function OnTriggerEnter( other : Collider ) 
 {
     if (other.tag == "Player")
     {
         isSeen = true;
     }
 }

 function OnTriggerExit( other : Collider ) 
 {
     if (other.tag == "Player")
     {
         isSeen = false;
     }
 }
avatar image Cbjfan1 · Jul 31, 2012 at 06:01 AM 0
Share

Is "$$anonymous$$ove$$anonymous$$onster" the script that makes him follow you?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by venhip · Jul 27, 2012 at 02:07 AM

Well, to see if it is within view of any camera, you can check renderer.isVisible:

 if(renderer.isVisible) //Checks to see if is viewed by a camera

if you mean, is it in line of sight of the character, that's a bit more complicated though, you would probably use a raycast forward from the character object... Beware: This includes if it is viewed by the editor camera, so while simulating your scene, if your enemy runs where your editor camera is looking, it will output if(renderer.isVisible) as true, so you'd have to be careful to make sure during testing that the camera is looking at the sky or something.

Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

Can unity3d combined with Artificial Intelligent or Soft Computing? 3 Answers

Script for collectiong keys to escape 2 Answers

Timed object destructor help! 1 Answer

NPC flying towards me!!! 1 Answer

Friendly NPC to Enemy (C#) 1 Answer


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