• 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 minhthinh · Dec 01, 2013 at 11:43 PM · itweendetectioncollison

Unity high speed collision detect

Hi all, I move a game object by itween and need detect some collision. But the moving speed so fast , so that I can not detect the collision. Are there any way for this solution (don't change the Fixed timestep). Thanks.

Comment

People who like this

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

Answer by keyp3r · Dec 01, 2013 at 11:55 PM

Absolutely. This should get you where need to be:

 public LayerMask CastMask;
  
 Vector3 oldPos;
 
 void Start(){
     oldPos = transform.position;
 }
 
 void Update(){
     //Move the object forward here...
     if(Physics.Linecast(oldPos, transform.position, out Hit, CastMask)){
         transform.position = Hit.point;
         //I hit something! Put a script call here...
     }
     oldPos = transform.position;
 }


So, what I'm doing there is moving the object forward, then drawing a line from my previous position to where I am currently and if I've found any object in-between we can assume that I should have hit it. Then I store my current position for use on the next frame. Going this route is great, because it means you likely dont need a collider on the moving object (at least for this to work), and it also means your collision detection is driven using the layerMask at the top there. You just need to make sure you set up your layers and check only the applicable ones in the layerMask.

Hope this helps! = )

Comment
MojopinStudios
ILoveBoobsMoreThanFreeWifi

People who like this

2 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 Hoeloe · Dec 02, 2013 at 12:01 AM 0
Share

This assumes your object is a point, which it almost certainly isn't.

avatar image keyp3r · Dec 02, 2013 at 12:28 AM 0
Share

Sure, but if it isn't then you can generally use a spherecast or capsulecast. If not, then no, this wont work, you're right. But if it is a small object, like a bullet, then a point cast is most efficient, clean, and simple. And if it's something like a character then a capsule cast should work fine as well.

avatar image

Answer by Hoeloe · Dec 02, 2013 at 12:03 AM

You'd have to do your own collision detection. The problem with this issue is that things don't really "move" in your game - they jump between discrete points when the frame updates. This means that if they're moving too fast, they can be on one side of an object in one frame, and jump to the other side when the frame refreshes. There's nothing you can do about this - it's just a fact of how computer simulation works.

What you can do is approximate where the object went in that last frame. The reason you're not getting collisions here is that you're only testing where the object actually is at any given moment. What you really need to test is all the locations the object was between the current frame and the last one. This is quite a lot more complicated, and you really have to estimate it, since you don't know for certainty exactly how the object travelled between the two points you have - only that it did. What you'll really need to do is create some sort of mathematical description of your collider, and "stretch" it between the points, so they it encompasses everything it would have hit in between. Linear interpolation is usually a reasonable approximation, and pretty easy to do, at least for box colliders.

Here's an example of how it might work, and hopefully it illustrates the problem and the solution reasonably well. For other colliders, you may want to use a more complex method, or just sample the collider with a bunch of linecasts:

An example in 2D of a BoxCollider approximation


continuous collision example.png (28.3 kB)
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 JamesWaterville · Nov 27, 2017 at 09:26 PM

If you have a rigidbody component attached to your high speed game object, you can set the "Collision Detection" to "Continuous". Continuous collision detection is recommended by Unity if you are having issues with high velocity objects. Using the Continuous setting will have a big impact on Unity's physics performance so only apply it when absolutely necessary.

Depending on what you're trying to collide with you may need to experiment with different collision detection settings. Please refer to the following Unity documentation: https://docs.unity3d.com/ScriptReference/Rigidbody-collisionDetectionMode.html.

Comment
BrightFyre

People who like this

1 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 BrightFyre · May 09, 2020 at 03:10 PM 0
Share

Thank you so much! This was all I needed!

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

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

Related Questions

Raycast and actions. 1 Answer

How to Set a cut off point where I cant click on my object 1 Answer

Unity collision detection is not working 1 Answer

How to program a bunch of 1st person animations at different speeds? 0 Answers

Trying to make a procedurally generated dungeon (3D), but rooms won't spawn 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