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 ShinyTaco · Nov 11, 2013 at 10:43 PM · rigidbodycolliderdrag

How to Stop a Game Object from Passing through a Collider while it's being Dragged?

I have game objects with rigid bodies and box colliders attached to them. I also have a script attached to them that allows me to click and drag them around when the mouse button is down.

However, when I click and drag them around and pass through the ground, which also has a rigid body and box collider on it, the game object that I am dragging around passes through the collider.

That's the problem.

How can you stop the game object that is being dragged around from passing through the ground while it's being dragged?

The game object should just stop being dragged when it hits the ground, not pass through it.

Any help is appreciated.

Thanks in advance.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mattssonon · Nov 11, 2013 at 11:02 PM

Use Rigidbody.MovePosition() to move the Game Objects. If you use, say, Translate() colliders won't behave like you want them to.

Comment
Add comment · Show 3 · 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 Owen-Reynolds · Nov 11, 2013 at 11:19 PM 0
Share

Right idea, but I think even $$anonymous$$ovePosition will gladly put the object through a wall. If you keep the movements very small (like current position + tiny bit) physics will correctly "pop out" translate and $$anonymous$$ovePosition.

To be sure, think you need to go one step further and use AddForce (or set velocity directly.) But that can give the object an odd spring-like wiggle.

avatar image ShinyTaco · Nov 12, 2013 at 07:19 AM 0
Share

I've tried both suggestions, it still passes through.

Any ideas for using OnCollisionEnter() or similar?

avatar image mattssonon · Nov 12, 2013 at 08:07 AM 0
Share

Well, you can use OnCollisionEnter() to check if it registers a collision at least. Try moving the objects further than normal with each drag to see if @owen-reynolds is right.

avatar image
1

Answer by _Yash_ · Oct 04, 2015 at 08:50 AM

Here is the easy and great solution, its late but worth sharing so...it also answers Why and How... https://youtu.be/ZfjVR-0ZFHU hope it will be helpful.

Comment
Add comment · Show 1 · 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 AzzaMan · Jan 04, 2018 at 08:28 PM 0
Share

Thank you Yash :) , the video in your link solves this problem.

avatar image
0

Answer by Owen-Reynolds · Nov 13, 2013 at 03:13 PM

If using only Addforce is putting your object through the ground, then something else is wrong. Maybe another part of the script, or some other script is messing up, or the set-up is wrong (triggers? bad layers -- but that can't happen by mistake.) Unless the speeds are crazy high (depends on the command.)

Maybe copy the scene, try just dropping the object on the ground (start it so it falls) and comment out parts of the the script so it just gives a single push/move/whatever.)

Also, the ground doesn't need a rigidbody -- just a collider. A rigidbody won't hurt (but then the ground will fall,) and can check isKinematic (but then easier just not to have it.)

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

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

Related Questions

Objects with colliders going through walls and each other. 3 Answers

Increase Drag Distance?? 0 Answers

How to block dragging if collider hits 1 Answer

Weird translation after instantiating on transform.rotation 2 Answers

Bouncing a rigidbody on a rigidbody 0 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