• 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
Question by sparkzbarca · Jul 18, 2013 at 05:03 PM · c#mathvectors

How to find an intercept on a moving target

So here is my code roughly

 Distance = Vector3.Distance(transform.position,Target.transform.position);
 float timeToTarget; 
 float burnDistance =  Projectile.MetersPerSecond * 2f * 2f * 0.5f;
 
 if (Distance < burnDistance)
 {
     timeToTarget = Mathf.Sqrt(2 * Distance / Projectile.MetersPerSecond);
 }
 else
 {
     float velocity = Projectile.MetersPerSecond * 2;
     TimeToTarget = 2 + (Distance - burnDistance) / velocity;
 }
 AimPoint = Target.transform.position + (Target.transform.rigidbody.velocity * TimeToTarget) + (Random.insideUnitSphere * Accuracy);
 Distance = Vector3.Distance(transform.position,AimPoint);
 TimeToTarget = Mathf.Sqrt(2 * Distance / Projectile.MetersPerSecond);

i'm trying to intercept a target with a projectile.

The issue is finding the proper time to target I think.

Basically when I find the distance to target then use that to find the time to target it changes my aimpoint to where the target will be in time seconds. But now the distance has changed. Now i'm now longer distance to target away i'm distance to aimpoint away from what i want to hit.

Basically as the target moves away from me it takes longer for the projectile to hit the aimpoint than is predicted by distance to target. So I can fix this somewhat by running the algorithm again. Only using the aimpoint as the target and getting a closer approximation. I could keep doing this to get really close but that seems highly ineffiecient. Is there a better way?

Comment

People who like this

0 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 HappyMoo · Jan 12, 2014 at 02:21 PM 0
Share

Please revisit your open questions and accept the answers you've been given. You seem to abandon a lot of your questions as soon as you have your answers. Either accept an answer or state what is still missing to accept an answer, don't let them open forever if they have been answered

avatar image sparkzbarca · Jan 12, 2014 at 07:34 PM 0
Share

I checked my own profile i have a total of 62 questions 10 of which actually had any answers at all and werent marked answered. one of which is this question posted 7 months a go and recieved no reply until 5 days ago which explains why it is isnt answered. another of which was a failure simply to mark my own posted answer reply as the answer and of the remaining 8 i checked them and dont view most of them as having been a reply that actually answers the question. I'd have to self post a reply and mark myself as answered (which I do on occasion thats why of my 5 pages of replies the last 3 and a half are all marked answered) but to suggest that what amounts to 4 or 5 unmarked questions is abandoning most seems extreme. If I abandon questions at all its only because i don't ask questions with simple 1 code line replies. Often I dont get replies because of the complexity of the question.

avatar image HappyMoo · Jan 12, 2014 at 08:05 PM 0
Share

You're right, "a lot" was way out of proportions. Let me rephrase: If the last action on one of your questions was an answer, common decency dictates that you at least reply to the guy that took some time to try to answer and tell him why this answer can't be accepted. I actually only bothered to comment here, because I considered trying to answer a question of yours, but then saw some old blue questions where you got an answer and then never replied or accepted. Anyway, I see you've gone back and accepted at least one old one I've seen, so that's good...

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Bunny83 · Jan 12, 2014 at 05:38 PM

This question has been asked around 5 times here on UA:

http://answers.unity3d.com/questions/296949/how-to-calculate-a-position-to-fire-at.html

Comment

People who like this

0 Show 0 · 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

Answer by Mutain · Jan 06, 2014 at 10:41 PM

take a look at this post http://stackoverflow.com/questions/2248876/2d-game-fire-at-a-moving-target-by-predicting-intersection-of-projectile-and-u

Comment
sparkzbarca

People who like this

1 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Find Vector3 perpendicular to Vector3 A in direction of Vector3 B 1 Answer

Distribute terrain in zones 3 Answers

How would you fake air resistance? (c#) 2 Answers

How to get a weighted random Vector2 between 3 points 1 Answer

Multiple Cars not working 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