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 Ted 1 · May 10, 2011 at 09:45 AM · collisiondetectionnullcontinuous

Null Collision Detection

Hello!Sorry for the newbish question but how can i create a boolean variable that returns true if the object is colliding and false when it is not colliding with anything?I searched for it all the morning but found nothing.

var bool : boolean = true;

function OnCollisionStay(){ bool = true; }

function OnCollisionExit(){ bool = false; }

^ That didn't worked because as my object exits the collision on another object it will return true all of the time. :[ Please help me

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

Answer by Aldwoni_legacy · May 10, 2011 at 09:53 AM

Have you tried OnCollisionEnter instead of OnCollisionStay?

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 Ted 1 · May 10, 2011 at 09:53 AM 0
Share

Yes,the same thing

avatar image Ted 1 · May 10, 2011 at 10:03 AM 0
Share

And beside that i don't want to test when it exits a collision,i want it to tell me when it is not colliding with something.Like : When my cube is in the air bool = false and when it is on the ground or touching something bool = true

avatar image
0

Answer by Senhor de todo o Mal · May 10, 2011 at 10:11 AM

Try this:

var colliding:int = 0;

function OnCollisionEnter(collision : Collision):void{ colliding++; }

function OnCollisionExit(collision : Collision):void{ colliding--; }

Note that collision events are only sent if one of the colliders also has a non-kinematic rigid body attached.

EDIT:

You can also try using Physics.OverlapSphere or Physics.CheckCapsule instead.

Comment
Add comment · Show 8 · 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 Ted 1 · May 10, 2011 at 10:25 AM 0
Share

Hmm.Looks like both of them worked if i would have used rigidbody.addForce or addVelocity ins$$anonymous$$d of rigidbody.position = Vector3(0,1,0) for leaving the collison.But why?I need to use the position one since i need my object has to follow the curosr

avatar image Ted 1 · May 10, 2011 at 10:28 AM 0
Share

If i use something like : if(Input.Get$$anonymous$$ey("b")){rigidbody.position = anotherGameObject.position} OnExitCollision wont work

avatar image Senhor de todo o Mal · May 10, 2011 at 10:42 AM 0
Share

When you alter position directly, collision is not checked.

avatar image Ted 1 · May 10, 2011 at 10:46 AM 0
Share

Hmmm,then is there any way of checking if my object is touching another object with a collider on it?

avatar image Senhor de todo o Mal · May 10, 2011 at 10:48 AM 0
Share

You can try using Physics.CheckCapsule or Physics.OverlapSphere

Show more comments

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

Why isn't continuous collision detection working on terrain? 1 Answer

chronological order of collision to give a winner unity 2d 4.3 1 Answer

Collision Enter one of the objects ? 1 Answer

Collision detection how? 1 Answer

Transferring values from one script to another script? 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