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 Borgo · Jan 28, 2011 at 05:48 PM · collisioncollider

How do I get a Not collision?

I need to create a box with a collider that need to check if there is NO collision.

How can I can do this?

Edit:

It's needed to be checked as soon is possible, if I use a variable that is altered inside a function, then I have 1 frame delay.

If I need to create about 200 box it will be a delay about 3 seconds.

My goal is to create a pathfinder, it will create an box, that will create some boxes, that will create another boxes and so on.

So, I need the collision be checked as soon is possible, like in their creation.

Thanks.

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

5 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Eric5h5 · Jan 28, 2011 at 08:53 PM

private var collisionCount = 0;

function OnCollisionEnter () { collisionCount++; }

function OnCollisionExit () { collisionCount--; }

function Update () { if (collisionCount == 0) { Debug.Log ("No collision"); } }

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 PrimeDerektive · Jan 31, 2011 at 07:22 PM 0
Share

Question about OnCollisionExit(), when does it actually get fired? Any object that collides with a rigidbody isn't going to actually "exit" it, unless it is kinematic, right? Would "OnCollisionEnd" be a better name for it?

avatar image Eric5h5 · Jan 31, 2011 at 11:26 PM 0
Share

Yeah, it probably would.

avatar image
2

Answer by DaveA · Jan 28, 2011 at 06:00 PM

Check that there is a collision, and if none, assume not.

Comment
Add comment · Show 5 · 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 Borgo · Jan 28, 2011 at 06:06 PM 0
Share

how? The OnCollisionEnter is a function. It is called just when there is a collision and don't have a return. I can't use a such thing like this: if(!Collider.OnCollisionStay(...))

avatar image DaveA · Jan 28, 2011 at 09:29 PM 0
Share

If OnCollisionEnter is not called, assume it's not hit. $$anonymous$$inda like what Eric suggests

avatar image Bunny83 · Jan 28, 2011 at 11:52 PM 0
Share

There is a big difference. Eric's version keep the information that there is actually no collision. OnCollisionEnter is only called in that frame where the intersection starts. During the collision OnCollisionEnter is not called anymore. OnCollisionStay is called every frame as long as there is a intersection.

avatar image DaveA · Jan 29, 2011 at 12:14 AM 0
Share

Yes OnCollisionStay is better

avatar image Eric5h5 · Jan 31, 2011 at 11:25 PM 0
Share

I wouldn't say it's "better". It has its uses, but it's called every frame as long as there is at least one contact, so it's better if you don't use it if you don't need to. So in this case it would be worse.

avatar image
1

Answer by Chilling · Mar 18, 2014 at 06:52 PM

This works for me (C#).

void FixedUpdate(){

 staying = false;        

}

void OnTriggerStay(Collider other){

     if(other.collider.CompareTag("SomeTag")){
         staying = true;
         
 }

}

void Update(){

 if(staying){
     Debug.Log("Colliding");
 }else{
     Debug.Log("Not colliding");
 }

}

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 Borgo · Jan 28, 2011 at 06:48 PM

I found this: Physics.CheckSphere

Returns true if there are any colliders touching the sphere defined by position and radius in world coordinates

Its check if a place is empty and return true or false.
The only problem is that it is not a cube, its a sphere.

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 PrimeDerektive · Jan 28, 2011 at 08:42 PM

private var wasHit : boolean = false;

function Update(){ if(wasHit == false){ Debug.Log("I am not being hit during this frame."); } }

function OnCollisionEnter (hit : Collision){ wasHit = true; }

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 Bunny83 · Jan 28, 2011 at 11:18 PM 0
Share

That would have been my approach but don't use OnCollisionEnter it's better to use OnCollisionStay. And in your Update loop at the end you should set wasHit to false for the next frame.

avatar image PrimeDerektive · Jan 29, 2011 at 02:58 AM 0
Share

Yeah that was a bit off the cuff just to get him started... I actually like Eric's solution the best.

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Collider Error[SOLVED] 2 Answers

Cover mechanic - Restrict movement to box 1 Answer

Hit Collision with exceptions 2 Answers

Trigger Enter and Exit not working properly? 2 Answers


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