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 ravi_gohil999 · Jan 13, 2014 at 04:40 AM · collisiondetectionrigidbody-collisioncollisionhandling

onCollisionEnter not working for ContinuousDynamic collision detection mode

Hi Guys, I am working on a game that needs to change the collision detection mode from Discrete to Continuous Dynamic and then once it collided, back to Discrete.

Well, it changes from Discrete to ContinuousDynamic but does not change frmo ContinuousDynamic to Discrete.

I am putting the code here using UnityEngine; using System.Collections;

public class freezePositionScript : MonoBehaviour { bool collidedWithFloor = false; bool changeMode = false; // Use this for initialization void Start () {

 }
 
 // Update is called once per frame
 void FixedUpdate () {
     if(laserCollision.placeObject && laserCollision._collidingObject.gameObject.name == this.gameObject.name)
     {
         print ("Placing object in FreezePosition");
         this.rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous;    
     }
     
     print ("collided with floor "+collidedWithFloor);
     if(collidedWithFloor)
     {
         //this.rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
         
         //this.rigidbody.constraints = RigidbodyConstraints.FreezePosition;
         
         //this.rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
         print ("Collision mode is "+this.rigidbody.collisionDetectionMode);
         print ("Freezing position for "+this.gameObject.name);
         changeMode = true;
         collidedWithFloor = false;
     }
     if(changeMode)
     {
         this.rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
         
         changeMode = false;
     }
     
     
 }
 
 void OnCollisionEnter(Collision col)
 {
     
     collidedWithFloor = true;
     print ("Collides in freeze position script");
     
     
 }
 void onCollisionStay(Collision col)
 {
     print ("Collsion for freezing the object");
     
     if(laserCollision.placeObject && laserCollision._collidingObject.gameObject.name == this.gameObject.name && collidedWithFloor)
     {
         
     }
     
 
 }
 

}

this script is applied to an object like Banana. After the collision detection mode is changed to Continuous Dynamic, the banana keeps on Jumping.

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 mohanrao164 · Jan 13, 2014 at 05:08 AM 0
Share

try onCollisionExit function .if there is no collisions this function is called so when there is no collision u can change the mode to Discrete hope this would helpfull

avatar image ravi_gohil999 · Jan 13, 2014 at 05:14 AM 0
Share

Thanks $$anonymous$$ohan but I have one constraint. When the object is falling, there is no collision so the collision with the collsion on object will not work. I have to use ContinuousDynamic mode because if the object falls on the ground, it must not go into space. With discrete collision mode the object goes below the ground and into blue space.

avatar image mohanrao164 · Jan 13, 2014 at 05:26 AM 0
Share

onCollision exit and discrete will not deactivate the collider of the gameobject .so when it is falling somewhere the collider is deactivating and passing through the wall so can u check on that.

1 Reply

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

Answer by ravi_gohil999 · Jan 13, 2014 at 06:40 AM

I have found an awesome script

http://wiki.unity3d.com/index.php?title=DontGoThroughThings

this things works well. Simple to implement. Make sure you assign the appropriate layer mask in the inspector when you use this script.

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

19 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 avatar image avatar image

Related Questions

Find axis of collision 0 Answers

Collision Handling (Pushout and Sliding) for Customized Collision Object? 0 Answers

AI Avoidance Problem 1 Answer

Unity changes the collisionDetectionMode in builds 1 Answer

Problems with DragRigidBody.js 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