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
1
Question by MaGuSware™ · Dec 26, 2012 at 05:30 PM · c#collisionphysicsrigidbodyphysx

What is the best way to prevent a physics object from going through thin colliders?

^.

What is the best way? Here is an example from my project...

I have a grenade, (well, it's just a ball really), and I throw it (at full power) towards my door and because the ball moves so fast and the door is so thin, the physics update will position it behind the door and not detecting the collision. I thought the PhysX calculations automatically compensated for this... but I guess not.

I want to avoid using the linecast/re-position method if possible as that is just a line, not a volume check... meaning it will clip corners.

Comment
Add comment · Show 12
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 Fattie · Dec 26, 2012 at 05:40 PM 0
Share

in some case, the extremely simple solution is .........making the wall/floor REALLY THIC$$anonymous$$ ! it's just that simple. it's an ingenious solution.

(however if in your case it's literally a door, this may not be possible? or, you will possibly have to just swap away the "incredibly thick" collider when you open the door - or whatever. you'll have to use Physics Layers, for sure, also.)

hope t helps! that's the usual "natty" solution

avatar image Fattie · Dec 26, 2012 at 05:50 PM 0
Share

Another good point - if it's going THAT FAST, it could be going way too fast.

Don't forget in game engines you do not do bullets and lasers with an object that moves. You just cast and see if you're going to hit, and then do the explosion (and perhaps draw a long "streak" for the laser/trace).

avatar image MaGuSware™ · Dec 26, 2012 at 05:52 PM 0
Share

That sounds like a really nasty way of doing it. As you say, for floors etc. it will be fine. The really thick collider will cause other problems, like if the grenade is going past the door.

avatar image Fattie · Dec 26, 2012 at 05:58 PM 0
Share

it's not in the slightest nasty, it's correct engineering and how every big commercial game you've ever played works !

often with things like doors, you do have to change colliders and so on depending on the position, and you have to use physics laters.

also there are a number of solutions explained by Lovrenc, such as simply calculating if you've passed each frame.

game physics is hard!

avatar image Fattie · Dec 26, 2012 at 06:41 PM 1
Share

What a cock situation. I'm really sorry I can't help, I would have thought for sure that would work fine. Just for the record - there isn't some nonsense happening like, it's going past the side or something?

$$anonymous$$y only suggestion, temporarily change it to 40cm thickness and it should work flawlessly. It's totally strange to me so maybe there's some other woe!

BTW is this ON YOUR ACTUAL IPAD?? could be some screwage on your desktop editor. Sorry can't help more. You'll have to use some annoying solution.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Setzer22 · Dec 26, 2012 at 06:55 PM

Usually the best sollution for really fast-moving objects is using raycast (even if setting the dectecion at continuous dynamic it can still fail and it can hurt your performance).

The script logic you need is something like this:

At start:

  • We add the grenade's position to a variable, let's call it lastPos

Each frame (in update):

  • We add the new grenade's position to a variable (newPos)

  • Then, we create a rayCast from lastPos to newPos

  • We check if the raycast collides with anything from lastPos to newPos

  • if it has collided, a collission has been skipped between frames due to the grenade's speed

  • We change the position of the grenade to stay behind the collider (not on the collider but a little far from it, to ensure the collision on the next frame

  • You might want to reduce the grenade's velocity at this point as well

  • Lastly, you set lastPos to the new grenade's position

As you can see, the problem is the continuous collision detection the raycast is doing (this might hurt performance as well), but I have found this method to be the best sollution for fast moving objects. (When i do bullets i usually do it only with raycast and totally forget about gameObjects, but in the case of a grenade this'll do fine)

I'm sorry I cannot write an script for you, but It's been a time since I last used raycast and colliders and I wouldn't write it well.

Hope it helped!

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 MaGuSware™ · Dec 26, 2012 at 07:05 PM 0
Share

I am already doing this (although I am using linecast ins$$anonymous$$d of ray). But I am looking for a different method for this, one which which will take the whole thing into account, for when going past corners.

If anyone is interested in the code for it btw, this is it.

     RaycastHit hit;
     if(Physics.Linecast(m_vPreviousPosition, transform.position, out hit))
     {
         if (hit.collider)
         {
             transform.position = hit.point;
         }
        }
     
     m_vPreviousPosition = transform.position;

avatar image
3

Answer by Lovrenc · Dec 26, 2012 at 05:42 PM

Physics is updated 50 times per second. If your projectile is moving so fast that between 2 checks it completely passes the door the engine cannot really catch that.


simmilar question

Quote: To fix this, you can use the built-in Unity tools - particularly, setting a moving object like your plank to "Continuous Dynamic" collision in its rigidbody settings, and setting the floor to "Continuous" collision. If you are using mobile devices though, this will probably be too expensive. In those cases, you can also just use thicker objects - if you need to use a thin plank, you can also make the floor thicker.

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 MaGuSware™ · Dec 26, 2012 at 05:49 PM 0
Share

This half works, it stops them from going all the way through, however, they are now embedded in the door XD

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

12 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

Related Questions

Excluding some physics collisions 3 Answers

rigidbody2D.addforce in collider 1 Answer

I need the ability to disable the functionality of a Rigidbody without deactivating it's GameObject, removing it, or changing any of it's physics settings 0 Answers

Vibrating GameObjects 0 Answers

Why can't my enemies walk up an incline? 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