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 /
This question was closed May 31, 2014 at 12:01 AM by meat5000 for the following reason:

Too subjective and argumentative. We can't walk you through to completion. For new problems, submit a new question.

avatar image
0
Question by Alvbatross_ · May 29, 2014 at 10:18 AM · enemyblinkingvisionmaincamera

How can you make an enemy follow you only when look away or blink?

Ok, I am beginner in unity, I'm trying to make a weeping angel game. I have a script that allows the enemy to move when i look away and it totally works fine. I then continued on to make a blinking animation (two cubes closing together to block the view of the camera). It also works but the weeping angel stays still when i do that blinking animation. how can I make the enemy move the moment the animation occurs. That is my only problem, the enemy does not move when the blinking occurs.

Here is the enemy move when player looks away script.(javascript) var target : Transform;

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

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

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

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

//Sets the sound effect trigger to be false at start var soundTrigger : boolean = false;

//Defines your sound effect public var Sound : AudioClip;

//Defines whether the sound has been played before. private var HasPlayed : 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 = 30; transform.rotation.x = 0; transform.rotation.z = 0; }/

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;
 soundTrigger = true;
 }
 
 //If you are NOT looking at the object...
 if(!renderer.isVisible)
 {
 move = true;
 //resets sound variables
 HasPlayed = false;
 soundTrigger = false;
 }
 
 //If you are not looking at the object...
 if(move)
 {
 //Make him look at the target
 transform.LookAt(target);
 //Always follow the target
 transform.Translate(Vector3.forward * speed * Time.deltaTime);
 }
         //Sets the sound effect componnet. If the player is looking, the sound will play.
         if (soundTrigger)
         {
             //Make sure the sound effect has not been played before. (Without this, this tends to lead to a repeated playing of the sound effect with every frame
             if(!HasPlayed)
             {
             audio.PlayOneShot(Sound);
             //Sets boolean to define that the above sound has been play already, and does not need to be played again while the player is looking at the target.
             HasPlayed = true;
             }
         }
 //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);
 }

}

Comment
Add comment · Show 3
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 meat5000 ♦ · May 29, 2014 at 10:24 AM 2
Share

isVisible Camera function perhaps

avatar image Alvbatross_ · May 30, 2014 at 12:01 AM 0
Share

what do you mean?

avatar image Alvbatross_ · May 30, 2014 at 01:25 AM 0
Share

I have another problem, the enemies can walk straight through the walls. I'm trying to make a level in my game that has the player trapped inside a house, but the enemy just goes through the walls, ins$$anonymous$$d of getting blocked by the walls

1 Reply

  • Sort: 
avatar image
0

Answer by Kiwasi · May 30, 2014 at 12:11 AM

I haven't read through your code in detail, but here is the meta code to solve your problem.

 //set a bool to true each time the blinking animation plays
 private bool isBlinking;
 
 if (isBlinking){
     //Do your move code in here
 }
Comment
Add comment · Show 3 · 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 Alvbatross_ · May 30, 2014 at 12:34 PM 0
Share

I made this new movement script( I will still use my 1st script, this is just an add on script) It won't work, could you please tell me the problem?

 #pragma strict
 
 var target : Transform;
 var pos : Transform;
 var speed : float;
 var blinking : boolean = false;
 var move : boolean = false;
 var soundTrigger : boolean = false;
 
 public var Sound : AudioClip;
 
 private var HasPlayed : boolean = false;
 
 function Update () 
 {
     if(Input.Get$$anonymous$$ouseButtonDown(1))
     {
         blinking = true;
     }
     else
     {
         blinking = false;
     }
     
     if(blinking == false);
     {
     move = false;
     soundTrigger = true;
     }
     
     if(blinking == true);
     {
     move = true;
     soundTrigger = false;
     HasPlayed = false;
     }
 }
avatar image Kiwasi · May 30, 2014 at 11:02 PM 0
Share

With this code blinking will only return true on the frame that the user clicks.

Try adding a timer that lasts the length of the blinking animation before setting blinking to false.

avatar image Alvbatross_ · May 31, 2014 at 01:18 AM 0
Share

ok thanks

Follow this Question

Answers Answers and Comments

22 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

Related Questions

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

How to update scoreline on a HIT? 1 Answer

Player damage stops working over time 0 Answers

enemy animations 1 Answer

Enemy AI With changing Player 0 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