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 therealbrandon · Aug 10, 2013 at 09:10 PM · movementaipath

How can I get an object to intercept a moving object's path?

I have been unsuccessful in trying to find an answer to this question on Google based on wording.

If I have a stationary object and there is a moving object coming near it, how can I set that object on a path to intercept the moving one? I have the very beginning of it, detecting when that object is within a certain radius, but now I'm wondering where do I start to calculate an intercept path based on the moving object's trajectory?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Aevek · Aug 11, 2013 at 04:43 AM

Basically, just Vector math. You're going to want to work out a how long your stationary object is (probably) going to take to get to an intercept point on the other one, then work out where the other one is going to be at that time, probably by multiplying that object's movement vector by the time.

You could also run a loop which moves the intercept point around until it finds the best match, knowing the other objects speed and path. It's problems like this that always prompt me to keep plenty of scratch paper near my desk.

But as a third point, typically for a basic 'zombie' AI, I just have the object move to where the moving object is, and that creates a nice chase thing.

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
avatar image
1

Answer by PoyrazGoksel · Mar 08, 2020 at 03:53 AM

 This is what i did using simple maths and physics works 100% precise
   
  /// <summary>
     /// <para>Since Laser speed is constant no need to calculate relative speed of laser to get interception pos!</para>
     /// <para>Calculates interception point between two moving objects where chaser speed is known but chaser vector is not known(Angle to fire at * LaserSpeed"*Sort of*")</para>
     /// <para>Can use System.Math and doubles to make this formula NASA like precision.</para>
     /// </summary>
     /// <param name="PC">Turret position</param>
     /// <param name="SC">Speed of laser</param>
     /// <param name="PR">Target initial position</param>
     /// <param name="VR">Target velocity vector</param>
     /// <returns>Interception Point as World Position</returns>
     public Vector3 CalculateInterceptionPoint3D(Vector3 PC, float SC, Vector3 PR, Vector3 VR)
     {
         //! Distance between turret and target
         Vector3 D = PC - PR;
 
         //! Scale of distance vector
         float d = D.magnitude;
 
         //! Speed of target scale of VR
         float SR = VR.magnitude;
 
         //% Quadratic EQUATION members = (ax)^2 + bx + c = 0
 
         float a = Mathf.Pow(SC, 2) - Mathf.Pow(SR, 2);
 
         float b = 2 * Vector3.Dot(D, VR);
 
         float c = -Vector3.Dot(D, D);
 
         if ((Mathf.Pow(b, 2) - (4 * (a * c))) < 0) //% The QUADRATIC FORMULA will not return a real number because sqrt(-value) is not a real number thus no interception
         {
             return Vector2.zero;//TODO: HERE, PREVENT TURRET FROM FIRING LASERS INSTEAD OF MAKING LASERS FIRE AT ZERO!
         }
         //% Quadratic FORMULA = x = (  -b+sqrt( ((b)^2) * 4*a*c )  ) / 2a
         float t = (-(b) + Mathf.Sqrt(Mathf.Pow(b, 2) - (4 * (a * c)))) / (2 * a);//% x = time to reach interception point which is = t
 
         //% Calculate point of interception as vector from calculating distance between target and interception by t * VelocityVector
         return ((t * VR) + PR);
     }

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
avatar image
0

Answer by rupakyeware · Sep 06, 2020 at 11:17 AM

@PoyrazGoksel how do I make my game object move to the point of interseption?

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

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

Random direction with Mouse Click... 2 Answers

How can I draw a ray for direction object is moving? 1 Answer

How do I make my AI move and follow me once I am close enough. 0 Answers

Sprite "shudders" on arrival 1 Answer

Getting my bullet to move in a straight line 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