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
1
Question by ThisGuyThatsHere · Feb 13, 2017 at 12:11 PM · collisionphysicsrigidbodyobjectdetection

Manually check collision ?

Hi,

So simply I want to check if my object collides with anything in one run from instantiation to potential destruction if it does. Is it even possible? I need to do this with meshcollider in mind, so sphere check is not an option, same for delayed "OnCollisionEnter/Stay" and RigidBody.SweepTest(Vector3.zero, out hit) does nothing (maybe I'm doing something wrong there with SweepTest).

Is getting all the bounds and spamming intersections all the way the only solution?

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 PizzaPie · Feb 13, 2017 at 02:24 PM 0
Share

According to SweepTest docs it won't work for $$anonymous$$esh Collider. As for the OnCollisionEnter should work as long the colliders are not triggers. Post some code for more help.

avatar image ThisGuyThatsHere PizzaPie · Feb 14, 2017 at 02:02 PM 0
Share

Well, yes, OnCollisionEnter works, but I wanted to make it check the collision just after instantiation so the code can decide what to do with object if it collides or not. $$anonymous$$y current solution is a little imperfect, as object decides what to do with itself some of new placement actions may be interrupted.

Code that I would like to have:

 bool CreatePart (ConnectionPoint c, Vector3 pos, Vector3 dir) {
     bool b = false;
 
     if (c.exists) { //Ignore this
 
         GameObject g = (GameObject) Instantiate(parts[id], pos, Quaternion.LookRotation(dir)); //Just instantiating the object
     }
 
     //And here is the problem, how do I check this collision? This bool is important later in the code and this is why OnCollision stuff doesn't work as solution
     if (g && !g.collides) b = true;
 
     return b;
 }



avatar image ThisGuyThatsHere · Feb 20, 2017 at 09:57 AM 0
Share

bump, can't believe you can't force collision check somehow in the same scope you instantiate object...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PixelSpartan · Feb 14, 2017 at 04:30 PM

You can just raycast to distance 0 and see if it tells you if you are inside something but make sure to go to physics settings and enable raycast hits triggers so it will also work for triggers

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 ThisGuyThatsHere · Feb 14, 2017 at 09:23 PM 0
Share

Not gonna work, It's not as simple as e.g. player falling through the floor, Im placing objects which have less or more advanced shapes and I need to know If new object will collide with existing ones considering high accuracy. Delayed OnCollisionEnter works, but makes a lot of mess and may disturb actions that are being taken in the same time that object got instantiated.

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

7 People are following this question.

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

Related Questions

Keep Horizontal Momentum after Jump 2 Answers

Collision.impulse = 0 in OnCollisionStay Kinematic Static collision pair after Update 0 Answers

How to change CC script to Rigidbody script 1 Answer

Joint or Collision without rigidbody 0 Answers

Why is there no Rigidbody2D.SweepTest() ? 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