Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 PaxStyle · Jan 27, 2016 at 10:06 AM · rigidbodyboxcolliderhit

RigidBody and Box collider Question

Hi! I have 4 objects that contain a rigidbody and a box collider each, when these objects hit each other, they change their position... I don't want that they change the position, but only that they stop when hit another object with the same box collider. I cannot remove the rigidbody because the script needs It. Any ideas? Thank you so much!

Comment
Add comment · Show 1
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 TheFloatingSheep · Jan 27, 2016 at 05:17 PM 0
Share

change velocity through script on collision with an object with that tag

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by LLIV · Jan 27, 2016 at 06:03 PM

What you're asking is a little backwards. You want the objects to behave with physics up until the animation is over and they touch. At least that's how I read it. If you truly just want them to stop when they touch I recommend that you use the rigidbody constraints on each object. Trigger them with oncollisionenter and they'll just stop. No movement no rotation.

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 PaxStyle · Jan 27, 2016 at 06:40 PM 0
Share

Without the box collider the objects enter one inside the other. So i have to find a solution but using the box collider. I tried the rigidbody constraints, but the problem is not solved. So, Can I use the box collider only as a component to prevent that the object enter one inside the other, without strange movement if these object touch both? alt text

yjyjy.jpg (357.3 kB)
avatar image LLIV PaxStyle · Jan 27, 2016 at 07:08 PM 0
Share

I think you misunderstand. You keep the box collider enabled on your object. You need to write a script that uses OnCollisionEnter to activate the rigidbody constraints or just using the kinematic property like FortisVenaliter said. function OnCollisionEnter () { Rigidbody.is$$anonymous$$inematic = true; } Format isn't correct but something like that.

avatar image PaxStyle LLIV · Jan 27, 2016 at 07:58 PM 0
Share

Ah ok! I added this to my script, but I have the same problem.. :/

 var rb: Rigidbody;
 
 function Start() {
     rb = GetComponent.<Rigidbody>();
 }
 
 function DisableRagdoll() {
     rb.is$$anonymous$$inematic = true;
     rb.detectCollisions = false;
 }
Show more comments
avatar image
1

Answer by JoshuaMcKenzie · Jan 27, 2016 at 09:29 PM

I think you want RigidBody.Sleep(), which should zero out all motion the rigidbody is currently tracking for the current frame. When the next frame starts the object will behave normally to collisions and gravity (unless kinematic is on), but will have lost all the inertia it had in the previous frame.

I believe you want to do this in both a OnCollisionEnter and OnCollisionExit check. Check if the collider you hit is the one that you want to stick to and if so call the sleep function. They can still be knocked around by other types of objects but the frame they "bounce off" their copies they reset their physics state.

OnCollisionEnter could work in preventing sliding along a surface, but if the objects overlap they might eject themselves from each other during the OnCollisionStay

OnCollisionStay wouldn't work because as long as the two bodies are touching they will be permanently put to sleep and would have to be moved by something other than a rigidbody component to wake up again

OnCollisionExit just helps in case the object were overlapping and thus get ejected.

of course I'm only making assumptions at what you'd experience, I haven't seen what environments you are using, but I'm sure you'll want Sleep() and you can experiment which combination works best for you

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 YouYouMobile · Jan 27, 2016 at 03:17 PM

Do you need physics in your game? What do you mean by stop? Just stay where they are?

If your objects are kinematics only (if you change their position yourself) you could set the colliders to "is trigger" in the inspector. Then use the functions OnTriggerEnter/Exit to detect collisions, and stop your objects' movement.

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 PaxStyle · Jan 27, 2016 at 04:52 PM 0
Share

The objects have an animation, when an object has done the animation cycle, It hits the others, but when It hits they, It change their position. It should only stops when hit the others objects.. To create this problem is the box collider, but I need it to separate the object, otherwise they merge together, So I have to use the rigidbody only to separet these object, but not as a fisic. I hope I explained quite well :)

avatar image FortisVenaliter · Jan 27, 2016 at 06:43 PM 0
Share

If you're only using the rigidbody to make sure the boxes don't intersect, there are other ways of doing that. Rigidbodies are designed to be much more comprehensive. You'll probably have an easier time of things if you just write a custom script to separate the objects manually. There are several guides for how to write that kind of algorithm online.

avatar image
0

Answer by FortisVenaliter · Jan 27, 2016 at 03:08 PM

The whole point of the rigidbody class is to handle physics calculations, and react accordingly. To disable those physics only when it hits collision (especially if you want to reenable them when the collision stops) could be tricky, because you're using the class outside of it's designed functionality.

That being said, the best I can come up with would be to have OnCollisionEnter and OnCollisionLeave handlers and to set or unset the RigidBody's isKinematic property where necessary, as when it's on, physics are disabled for that object.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how do you activate a sound effect when two objects with box colliders hit? 0 Answers

OnTriggerExit happens too soon! 1 Answer

Box collider on a moving object-shopping cart 3 Answers

Box collider (with Rigidbody attached) gets stuck into another Box Collider 0 Answers

Why do I get OnTriggerExit upon collision when a rigidbody is kinematic? (example) 3 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