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 andy_757 · Dec 01, 2013 at 08:47 PM · collision

Collision detection within 1 frame.

Is there a way to detect if a mesh collider and a capsule collider are intersecting without running a frame?

I would like to do this because I want to randomly spawn objects with mesh colliders in the level. However, there is a path which a character needs to move through. This path is defined by a chain of capsule colliders. In order to keep this path free from obstructions, I want to spawn random objects, but then immediately move/remove them if I detect that they are intersecting with one of these capsule colliders. I'd like to be able to do this all in one frame i.e.

  1. Spawn object

  2. Is object intersecting path capsule colliders? No: Goto 5, Yes: Goto 3

  3. Move object to new random location

  4. Goto 2

  5. Finish

I know I can do something like this if I complete one cycle per frame and listen to collision events. However I'd like to do as many cycles as needed in one frame.

Is it possible? Or is there another way I should achieve this?

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

2 Replies

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

Answer by robertbu · Dec 01, 2013 at 09:19 PM

There is nothing built-in that gives you this functionality. If you record the information about position, height and radius of each capsule, you can cycle through the array and use CheckCapsule() to see if anything intersects. You'll likely have to use layers and a layer mask to make this check only find your game object.

Another way is to have a bounding radius for the mesh for your spawned objects. You can then use CheckSphere() or OverlapSphere() to see if the position is valid. Note this will produce false positives. That is it will say there is an overlap in some cases where the position is close to the collider when in fact they don't overlap.

Another solution (which also produces false positives) is to check the bounds of the each capsule against the bounds of the spawned object for an intersection. You can use Bounds.Intersects() to make this check.

An efficient method is to create a radius bounds and compare the center point against the distance to all the line segments in the path. This assumes the path is fixed width. The code to calculate the distance to a line segment is available a number of places on the net including this one:

http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment

Comment
Add comment · 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
0

Answer by MarkD · Dec 01, 2013 at 09:05 PM

No, all calculations are done within time. and Update just happens to run simultaneously with frame on the time scale. so if you slow the time scale down, the frames will drop.

The processor of the pc itself runs with fps on the way it calculates data. (at least when you use update). The only thing you could do is use is the start function, that way everything from that spawn gets handled first, but will only be done once.

You need to make a checkup with an if or while statement that when a collider is hitting a collider it should move its location. But again if it needs to be happening only in frame 1, I would go with the function Start(){}.

I hope this makes any sense.

Comment
Add comment · 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

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

17 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

Related Questions

Immortal enemies when reanimated, or pooled game objects re-activated do not respond to collisions? 1 Answer

How do I use compute shaders with particles? 0 Answers

How do I check collision above? 1 Answer

Character Controller Collisions Question 1 Answer

how to make object follow mouse cursor while detecting collision 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