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 fourfourtwo · Aug 24, 2018 at 11:16 PM · collisiongameobjectcolliders

How to make two objects not go through each other (without physics)

I have two gameobjects, both with colliders on them and one with a rigidbody attached.

I am controlling one of them by changing its position. When I move one gameobject into the rigidbody gameobject, it passes through. How can I make it so that the two objects touch but never go through each other without the use of physics .


I assume it might work like this:

  1. Detect collision

  2. Record position and orientation at collision

  3. if next movement will move object into the other, reset position to recorded position


Any ideas if this is the right way and how to implement this? 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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 24, 2018 at 11:32 PM

Your question is very confusing. A rigidbody is a physics object. Any sort of collision is physics. So i'm not sure what you mean by "without physics". In order to properly detect collisions any moving object with a collider need to have a rigidbody attached.


Maybe you want no collision response? This is generally a bit difficult with physics. Maybe you want to use a CharacterController? The CharacterController is specifically designed to only detect collisions without being affected by other objects. Though a CharacterController has some restrictions. It always is a capsule and that capsule is always upright.


The behaviour you want is not really clear from your question.

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 fourfourtwo · Aug 25, 2018 at 10:20 PM 0
Share

The behaviour I want is such that when the two objects come into contact, they do not pass each other. What I mean by "without physics" is that I don't want to attach a rigidbody to the object that I am controlling because I am controlling it via transform.position. Is there a way to use a rigidbody AND control my object in this way (i.e. without applying force/torque)?

avatar image
0

Answer by JVene · Aug 25, 2018 at 12:37 AM

While I agree generally with Bunny83, I think I can guess at your meaning.


Our confusion comes from the fact we've studied this type software extensively (I say type because I'm recent to Unity, but I've worked on various game and physics engines), and we know that collision itself is the first part of the physics engine, so it is physics. I believe what you're saying is that you're not moving objects by physics. The standard step which follows a collision is to calculate the forces exerted as a result of the collision and apply those to the objects such that they correctly respond to having collided, with reference to the nature of the materials involved.


From what I can see, you have the basic idea, but there are lots of tributaries in thought and design which are beyond the scope of a post. That can become the domain of writing physics engines, something that is barely within undergraduate studies of mathematics, physics and programming.


When objects collide there's a counterforce that results, and if the direction of that force isn't correct the results look odd if the intent is to present a realistic physical behavior. In games, however, this is occasionally unimportant. Your list of steps would exhibit this error when compared to real physical collisions, so you have to decide if that matters.


The subtle error you appear to have in your list, however, is the recorded position at collision. This depends on whether or not your collision objects is larger than your visible object, and the speed is such that the results happen to look right. Instead of recording the position at collision, one must consider either to use the previous position, before the collision, or to calculate that position which results in contact minus a very minor margin, so it looks as though the objects touch but don't overlap.


If the objects are simple enough, you may do well enough with a capsule or sphere collider. If that can do, you can avoid physics collisions altogether and work merely on the distance between the center of the objects in question relative to the radii of the spheres and/or capsules. It is much faster, but can be an oversimplification.

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 Stratosome · Aug 25, 2018 at 02:47 AM

The others have already made answers, but in case you're looking for something different...


I'd suggest leaving your Rigidbody component on the object and use Unity's physics (unless you are really wanting to avoid it or something). If your only problem is that since you are setting the position of it, and because you are, they are going through each other, try setting its position using Rigidbody.MovePosition. Assuming it is the rigidbody you are moving around, it will still collide and stop moving when it comes into contact with another collider.

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

174 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 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 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 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 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 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 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 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 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

How to make UI(Gameobject) appear on collision enter? 0 Answers

Collision issues with game object 1 Answer

raycasts only working with IsTrigger colliders? 1 Answer

Collider2D.GetContacts() always returns only 1 contact 1 Answer

Get the script instance associated with a collider 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