Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by chearner · Apr 23, 2010 at 02:59 PM · aitargeting

How to determine a "cone of influence" used for targeting an object.

Can someone direct me on how to determine a cone of influence for an object in the distance.

Basically it would be used for AI targeting or tailing an object in a dogfight so that I can tell if my ship can shoot another ship.

I'm guessing you would take into consideration the speed, direction and distance of the objects to see if the target ship falls into an imaginary "cone" projected from my ship. If so I could "lock" it and shoot a missle or something.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by andeeee · Apr 23, 2010 at 03:11 PM

A cone like this is easily implemented using the dot product of the ships's forward direction and the vector pointing from the ship to the target (both vectors should be normalised). The result of the dot product will be the cosine of the angle between the two vectors (this will be 1 if they are aligned, 0 if they are at right angles and negative if the angle is > 90). Say you want a cone that spreads 30 all around the ship's forward vector. You would check if the dot product is greater than cos 30 and if so, the target is within the cone:-

var cone = Mathf.Cos(30 * Mathf.Deg2Rad); var heading = (target.position - ship.position).normalized;

if (Vector3.Dot(ship.forward, heading) > cone) { // Target is within the cone. }

Comment
Add comment · Show 1 · 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 cupsster · Dec 20, 2010 at 07:28 PM 0
Share

thank you! exactly what i was looking for...

avatar image
1

Answer by duck · Apr 23, 2010 at 03:12 PM

You could do this by converting the target's position to local coordinates, using InverseTransformPoint. Eg:

var targetLocalPosition = transform.InverseTransformPoint(target.position);

Next, you can check whether it's within a specified cone radiating out from the front of your ship - this is nice and easy now we have our target in coordinates that are local to the ship:

var targetZ = targetLocalPosition.z; var targetXY = Vector2(targetLocalPosition.x, targetLocalPosition.y);

if (targetZ < 0) { // target is behind us } else { if (targetZ > coneLength) { // target is beyond the end of the cone // (out of range in local Z) } else {

     // get the radius of the cone at the target's distance
     var coneRadius = (targetZ / coneLength) * coneBaseRadius;
     if (targetXY.magnitude &gt; coneRadius) {
         // target is outside of the cone
     } else {
         // target is within the cone! LOCK ON!

     }
 }

}

Comment
Add comment · Show 1 · 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 chearner · Aug 02, 2010 at 03:01 AM 0
Share

Thanks Duck, can you tell me why this has to be in local coordinates? $$anonymous$$aybe a brief description of why you need to translate it from world coordinates might help me wrap my brain around it. I thought local coords are useful when dealing with the screen, not a cone in 3d space. It says InverseTransformPoint is affected by scale, what does that mean? For example the object I'm tracking is 500 units wide, so how does relate to local coordinates radius. Also is that tracking the center point of an object regardless of how wide it might be (a very wide might not have the center point in cone).

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

No one has followed this question yet.

Related Questions

Targeting multiple tags 1 Answer

random target selection 2 Answers

Enemy AI targeting script 3 Answers

Targeting other objects of the same type but not self 1 Answer

Ai finding target after spawning 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