• 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 Sebi16 · Jul 08, 2016 at 08:53 PM · collisiondetectiontrajectory

How do you check if two objects WOULD collide if their trajectory reimains the same?

Is there any build-in function? If not, could you explain me the principle? Example: Two cars running at different speeds on two different streets which at some points cross. Can you know when & where would they collide if the drivers don't break?

Comment
Add comment · Show 1
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 Hellium · Jul 08, 2016 at 09:49 PM 0
Share

FAQ :

We want Unity Answers to become a comprehensive database of questions and answers related to Unity.

Your question is not directly related to Unity, this is a pure mathematical problem, and thus, does not belong to Unity Answers. You will easily find an answer of your problem on the Internet with scientific papers about the subject.

NB : If you check your mails, you will see I have let a comment before rejecting your question

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by elenzil · Jul 08, 2016 at 09:35 PM

if you approximate your objects as spheres, then you can set this up algebraicly.

 T0 = time now
 RA = radius of sphere A
 RB = radius of sphere B
 VA = velocity vector of A
 VB = velocity vector of B
 PA0 = position of sphere A at time 0
 PB0 = position of sphere B at time 0
 PA(t) = PA0 + VA * (t - T0)   // position of A at time t
 PB(t) = PB0 + VB * (t - T0)   // position of B at time t
     
 want to find:
 TC = time of collision, if any.
 
 so you want to find the moment when the distance between the spheres is exactly equal to the sum of their radii. ie, solving for TC in this formula:
 magnitude(PA(TC) - PB(TC)) = RA + RB.

 when you solve for TC you will get 0, 1 or 2 real solutions.
 if you get 2 solutions, the lesser of them is the moment of collision.
 if you get 1 solution (unlikely) then they just graze each other.
 if you get 0 solutions they don't collide.

 this approach does not deal with the case where the two spheres are already overlapping.
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 Kusras · Jul 08, 2016 at 09:52 PM

Maybe this could help you - https://docs.unity3d.com/ScriptReference/Rigidbody.SweepTest.html. with some math added

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 elenzil · Jul 08, 2016 at 10:33 PM 0
Share

this is a cool routine but i'm not sure it will work in this case, as the other object needs to be swept also, and you need to account for time. for example, if one car passes through the intersection long before the other car does, then their sweep volumes will intersect even tho the cars did not actually collide.

also, your URL has a dangling period on it.

avatar image
0

Answer by EDevJogos · Jul 08, 2016 at 09:33 PM

You could use a Raycast with x distance, if the trajectory remains the same eventualy the ray will collide with the other car, just set the direction of the ray to the other object you want to check if a collision is imenent.

https://docs.unity3d.com/ScriptReference/Physics.Raycast.html

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.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collision Detection When Picking Up GameObjects 1 Answer

OnCollisionEnter not working 1 Answer

collision detection fail 1 Answer

Collision detection of certain ojects 1 Answer

check if player is colliding with a trigger 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