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
0
Question by Charles_Gams · Apr 04, 2013 at 12:02 PM · enemyvision

Increase Field of vision of Enemy over time

I'm using Vector3.angle to determine when my enemy detects my player and it works fine. However i want it so that when the player is in the Enemy's 3rd alert stage meaning full detection the Vector3.angle increases so that the enemy can detect the player where he maybe for a period of time.

eg// full detection 22.5 and when this happens increase full detection to 180.0 for example

 Heres my code :
 
     function React()
     {
     // This function happens when Enemy is in Full alert depending on
     // Enemy they may Fight you or engage in close combat . 
     //They may shoot at you if they are equipped If they are not Equipped they will            
     //search for the closest object they can use in their surrondings and whatever that    
     //object maybe throw it at you or shoot /aim at you
     
        Debug.Log("Get Over Here You Scum!");
 
        transform.position = Vector3.MoveTowards(transform.position,P_target.position,        
        patrolSpeed * Time.deltaTime);
        animation.CrossFade("Walk");
     }
 
 
     function Detect()
     {
       // This function will be used for everything related for detection or the
     
       // characteristics of the enemy when detection. Meaning there will be 3 alert
     
       // stages and each stage has its own characteristics.*
       
         var targetDir = P_target.position - transform.position;
         var forward = transform.forward;
         var angle = Vector3.Angle(targetDir, forward);
         if (angle < 90.0)
         {
            Debug.Log("Huh");
         }
 
         if(angle<45.0)
         {
           Debug.Log("What The");
         }
 
         if(angle<22.5)
         {
           Debug.Log("Oi You");
           React();
         }
     }
Comment
Add comment · Show 5
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 Chronos-L · Apr 04, 2013 at 12:08 PM 0
Share

You should format your code using the 5th button from the left on top of the editor or highlighting all codes and press Ctrl-$$anonymous$$.

Furthermore, after you finish typing your question, before you publish it, you can scroll down to preview your question.

avatar image Charles_Gams · Apr 04, 2013 at 12:22 PM 0
Share

Thats strange it seems fine to me how exactly is the code displayed or formatted on your side

avatar image Chronos-L · Apr 04, 2013 at 12:35 PM 0
Share

I formatted it for you this once, so it seems fine.

avatar image Charles_Gams · Apr 04, 2013 at 12:52 PM 0
Share

Oh alright sorry about that and thanks

avatar image Charles_Gams · Apr 04, 2013 at 01:40 PM 0
Share

Any ideas I'v tried a couple things but can't get it working the way i want

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nachtmahr · Apr 04, 2013 at 12:26 PM

make a enum that holds your Detection State

Example

 public enum DetectionState{
 Invisible,
 FirstStage,
 SecondStage,
 ThirdStage,
 FullySpoted,
 etc,
 }
 
 function Update(){
 Detect();
 switch(CurrentDetectionState){
 case DetectionState.Invisible :
 //Do Stuff like set angle to 25 degress
 break;
 case DetectionState.FirstStage:
 //Do Stuff angle 60 degrees and other stuff
 break;
 //... and so on
 }
 }

you can use the same switch for your Detect Function.

I would normaly suggest something like a FinateStateMachine ;P

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 Charles_Gams · Apr 04, 2013 at 12:28 PM 0
Share

Yeah thats what I'm doing but never thought of using it for a detection state ill try that out

avatar image Charles_Gams · Apr 04, 2013 at 12:30 PM 0
Share

Plus i don't think it solves the problem because initially i want the enemy's field of vision to increase onces its fully detected you and once it can't see you it returns back to normal if that makes sense

avatar image Nachtmahr · Apr 04, 2013 at 12:42 PM 0
Share

add a float variable currentDetectionAngle and set it according to your state

case DetectionState.ThirdStage : currentDetectionAngle = 180; if(angle < currentDetectionAngle) //Do your stuff

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

12 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

Related Questions

Enemy shouldn't see you through walls 1 Answer

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

Enemy VISION range? Help! 0 Answers

Raycast stealth enemy? 1 Answer

Show only selected enemy's health bar 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