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
0
Question by Feref2 · Nov 17, 2019 at 11:06 PM · collision detectionoverlapping

How to check how much are two objects overlapping?

So there are functions that allow you to see if two objects are overlapping, but I think that they don´t tell you how much are they going through. I can´t use Unity´s physics system and am trying to get how much should an object be moved to return to where it originally collided.

Comment
Add comment · 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 Bonfire-Boy · Nov 18, 2019 at 11:13 AM 0
Share

Seems unlikely to me that looking at the overlap extent is going to be a good way to achieve what you're after.

What do you mean by "where it originally collided"? Why can't you cache the position you want it to return to?

avatar image Feref2 Bonfire-Boy · Nov 18, 2019 at 07:30 PM 0
Share

Because I don´t have that position, and because it´s difficult to get because are two objects moving to different directions at the same time the ones that will collide.

avatar image Bonfire-Boy Feref2 · Nov 18, 2019 at 07:38 PM 0
Share

So again, what do you mean by "where it originally collided"? Is the problem just that collision detection isn't precise enough for your purposes? If so then check that none of your objects are using discrete collision detection.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by VicciGames · Nov 22, 2019 at 03:20 AM

You might need to just use continuous collisions if you are having collision errors.


How come you cannot use Unity's physics system?

Are you having trouble with unnoticed collisions?


If so

Let's look at a scenario if you did use Unity Physics.


With Discrete collisions, Physics only detects when a frame passes. So, if an object happens to be positioned past a desired collision, it will miss at the time the frame is calculated.

To fix this (ccontinuous collisions) we need to Predict the collision. This involves shooting raycasts from close and far edge vertices that determine the distance from the next object BEFORE the frame of collision happens so we can then snap to the correct location ( or perhaps marginally position it/ or even slow down the object) to get a safe collision.


Just want to practice NOT using or CANNOT use Unity Physics?


Okay. well. I would say you need to calculate a Vector3 of atleast one of the objects and offset it when a collision is detected (Not using Unity: Use the above method)

I would create a vector3 at collision and calculate the difference between the current position of the object and the new vector3 and subtract it. Might look very ugly.


You can use a vectors magnitude for the size of the vector.


Just off the top of my brain.

Comment
Add comment · 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 Feref2 · Nov 22, 2019 at 06:09 AM 0
Share

Thanks, but I don´t understand your solution. Am I supposed to store the collision point in a Vector3 and get the difference between that and the center of the object that´s colliding right now? (Which would give the distance to an edge). And what do you mean by "use a vector magnitude for the size of the vector" (sorry if it´s a stupid question). By the way, I really CANNOT use Unity physics. They act modifying positions, but all the positions in my scene are defined by the scales of other objects (just imagine the ground getting bigger and smaller and moving things that way). I made linear collisions with raycasts, but I was having a hard time figuring out collisions between two moving objects. I think that I know now. If I somehow translate both movements into just one linear equation, I can do sweeptests and collision casts. The problem now is that that solution implies doing a rigidbody.sweeptest for every object in the scene each frame, which is terrible for performance (or am I wrong?). I was thinking in a way of reducing this calculations, so just if you know, is there an easyand practical way of doing this? Or a better approach?

avatar image Bonfire-Boy Feref2 · Nov 22, 2019 at 10:16 AM 1
Share

You wouldn't necessarily need to do a sweep test on every object every frame. For example you could do a less-expensive spherical overlap test first to see if a sweep test was necessary. You wouldn't necessarily need to do the test every frame.

Whether or not you're going to end up with performance problems depends on lots of things, I think you're just going to have to try stuff. Ultimately, if you're going to put your own physics system together it's going to have to do this sort of thing. PhysX doesn't come for free either.

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

120 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 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 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 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 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 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

Checking if object intersects? 1 Answer

Simplest way of detecting if there's an object at position X 1 Answer

[JS] Getting an Error In My Money System Script 1 Answer

OnCollisionStay2D - why is the list of contacts is incomplete? 0 Answers

Trying to get a gameObject to collide with particles in a particle system. 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