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
0
Question by BestMattEver · Jan 14, 2015 at 09:38 AM · collisionssweeptest

Rigidbody.sweeptest only seems to work when hitting certain object

Hi, I'm making a game with procedurally generated roads. to stop them from overlapping, I'm using Rigidbody.sweeptest to check for overlapping road sections as each new road section is laid down. This seems to work great, but only when the road section overlaps the starting tile. all other instances of overlap are ignored for some reason.

The starting tile is just a prefab object with some geo, a mesh collider, and 4 empties with scripts attached (road ends). the road sections themselves are prefabs with geo, a mesh collider, and two empties: one of which only has a script (road end) attached, and the other (road start) has a script, rigidbody and bounding box colliders (to assist in overlap checks).

The idea is that the rigidbody in the roadstart of each road section (and its colliders) would sweep just a hair up and down, and that would cause a true bool to be passed back. if true: try a different road section, etc...

here's a picture describing the problem:alt text

and here's the code where i try to detect the overlap (note that this happens for every road section and temproad is the road being laid down on this iteration):

 //turn off the road geo, so overlap check wont hit itself.
                     tempcollider = temproad.transform.Find ("RoadGeo");
                     tempcollider.gameObject.SetActive(false);
 
                         //Debug.Log(collisioninfo.collider);
                         /*if((collisioninfo.collider.gameObject.transform.parent == temproad))
                         {
                             //do nothing, you're colliding with yourself idiot.
                             Debug.Log ("self collision. ignore.");
                         }//end if        
                         else
                         {*/
 
                             //OMGoverlap = true;
 
                             //check for overlaps using the roadstart colliders
                             Debug.Log ("overlap: " + (temproad.GetComponentInChildren<RoadStartstuff>().gameObject.rigidbody.SweepTest(transform.up, out collisioninfo, 2.0f)) +" on " + totalroadcount);// if yes, send a debug message
                             OMGoverlap = false;
                         
                 
                     //turns back on roadgeo so players can drive on roads
                     tempcollider = temproad.transform.Find ("RoadGeo");
                     tempcollider.gameObject.SetActive(true);
                     
 
                     //turns the roadstart colliders into triggers so the player doesnt run into them
                     tempcollider = temproad.transform.Find ("RoadStart");
                     tempcollider.collider.isTrigger = true;
                     
                     //sets the number on each section of road so I can keep track of em.
                     temproad.GetComponentInChildren<RoadStartstuff>().iamroad = totalroadcount;
 
                     //tell the roadend we're working on that it is paired with a road... finally.
                     roadends[i].GetComponent<RoadEndStuff>().paired = true;


If you need anything else (like hierarchy maps of the game objects or more code or whatever) please let me know! I want to get this working! i have a girl i need to impress on saturday!"

only on start tile.jpg (155.7 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by BestMattEver · Jan 14, 2015 at 06:45 AM

HA! I figured it out! well, kinda. sweeptest wont work if the object you're sweeping starts already colliding with the object you're trying to see if it'll collide with. I guess it just disregards that collision... i only KINDA figured it out because while I have proper collisions now, that explanation still doesn't explain why i was getting it on the start tile (as the road sections were spawned touching it as well as the other road sections....)

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 XyloBeta · Aug 03, 2020 at 08:34 PM 1
Share

5 years later and this answer helped me get a good workaround. You're right, it doesn't regard the collider the rigidbody is on top of, so what I did was shift the position slightly up before the sweeptest and shifted it back down again. Thanks for your answer!!!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Tone down physics/collisions 2 Answers

Pixel Perfect Collision Possible? 3 Answers

Activate a GUI Text on Collision? 3 Answers

Objects 'Clumping' problem 1 Answer

Collisions layer is not appearing. 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