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 Aug 24, 2013 at 02:42 AM by DeadKenny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DeadKenny · Aug 22, 2013 at 05:41 PM · collisiontriggeraidirectioncontact

OnTrigger AI projectile detection and turn.

Ok I need to get my AI to notice bullets being shot into his line of sight and him.

He has 2 colliders, one is a trigger which is the vision collider and the other is the capsule collider on the AI itself(not a trigger).

What I need is this fool to detect or reference the angle at which the bullet is shot at him and start moving in that direction.

Code so far:

 void Update(){
 
     if(startSearching == true){
          
         Searching();
       
 }
 }
 
 //The hell am I doing lol? I don't know.
     
     void OnTriggerEnter(Collision colp){
     
     
       var contact = colp.contacts[0];
        
      if(status == Status.Idle){
     
       targetDirection = Vector3.Reflect(transform.forward, colp.contacts[0].normal);
     
       startSearching = true;
     
     
      }
     
     }
 
 
 void Searching(){
       
       // This makes it go forward.
       vSpeed = 1;
     
       // and this is the turing to contact point.
 
       tansform.rotation = Quaternion.LookRotation(targetDirection);
 
     }}


So what I am trying to say is... This whole thing does not work, I am very confused and please halp!!

Comment
Add comment · Show 2
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 DeadKenny · Aug 22, 2013 at 06:31 PM 0
Share

I'm using c# too...

cool busy making new code now.

avatar image DeadKenny · Aug 22, 2013 at 06:59 PM 0
Share

Ok it works but now its conflicting with the other stuff. However that should be easy to fix, thanks... I hope.

Thanks.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by sdgd · Aug 22, 2013 at 05:47 PM

java is not my best lang so I'll try to explain in comment

first

 Vector3 pos;
 
 void OnTriggerEnter(collider Bullet){
      pos = Bullet.transform.position-transform.position;
 }
 

something along this lines and first you'll figure out at what direction he's being shot at and after that you make him move in the opposite direction.

well depends what you actually want, ...

since I've been helpful i'm converting to an answer and here's some more information:

Transform Manual

OnTriggerEnter Manual

and you propably need to make another GameObject with only collider and attach the script to it (that will be a bullet detection collider).

if you give collider with witch AI is standing on "earth" a trigger you'll see the enemy AI fall down. so at least 1 collider must not be trigger.

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 DeadKenny · Aug 22, 2013 at 11:18 PM 0
Share

Thanks man.

avatar image sdgd · Aug 23, 2013 at 12:20 PM 0
Share

, ... you closed the Q and said the right answer was accepted

I don't see it accepted tho, ...

you accept it with the check mark under the thumbs down.

and after that my answer becomes green.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Enemy (with state machine) cannot target player!! 0 Answers

Can not get value out of a collision 1 Answer

Funny error. collision just hit 12 times 1 Answer

Collision without physical behaviour. 1 Answer

OnTriggerEnter Being Called On Unexpected Object 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