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
2
Question by douglasg14b · Mar 26, 2015 at 08:52 PM · collisionrigidbody

What is causing my object to spin around and act funky when it hits another collider?

I recently added a rigidbody to my gameobject so that I can recieve ontriggerenter/exit calls. Though if my new unit hits something else with a collider some odd behavior occurs.

http://i.imgur.com/KzMHR46.webm:

Whats causing this to happen? And how do I stop the object from moving in a seemingly unpredictable way if it hits another collider?

Comment
Add comment · Show 5
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 hexagonius · Mar 26, 2015 at 09:51 PM 0
Share

You might want to freeze rotation on x and y on the ship's rigidbody

avatar image douglasg14b · Mar 26, 2015 at 10:42 PM 0
Share

Yep that did the trick. Though what actually caused this? If I want to use any sort of physics on the future what sort of issues will I be tackling to avoid this specific problem?

avatar image lordlycastle · Mar 26, 2015 at 10:46 PM 0
Share

The problem is in your code, nothing we can help you with, without it.

avatar image douglasg14b · Mar 26, 2015 at 11:16 PM 0
Share

I mean, even with all the code removed (components disabled) that controls movement it still moves that way. I only have 1 class that controls that units movement, with that component disabled there is no further code of $$anonymous$$e that can cause it to move. The only way I can get movement is through that collider. I want to know what goes on with colliders and rigidbodies that causes such sporadic rotation and movement. And if I need to take steps to control that interaction in the future.

I can stop the rotation by setting up a loop to set the rotation to 0. Though even after that it goes back to rotating the moment the loop is not being ran.

avatar image lordlycastle · Mar 26, 2015 at 11:34 PM 0
Share

You should be using BoxCollider2D for sprites, not Sphere collider. That's why it's spinning in 3 dimensions.

1 Reply

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

Answer by Addyarb · Mar 26, 2015 at 11:17 PM

As stated in the comments to the original question, locking the axis will prevent this from happening. The reason your gameObject moves around when it gets hit is because "Rigidbody" is a component, that tells the object it is attached to, to simulate Physics when it interacts with another collider. If you don't want to simulate Physics, you can use other methods of detecting collision, or you can lock all of the axes.

However, it is recommended that if your object is moving and attempting to detect collision, that you have a Rigidbody component on it at all times. I believe this is because rigidbodies detect collision using FixedUpdate instead of Update, which is more exact and will give you a more accurate collision setup.

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 douglasg14b · Mar 26, 2015 at 11:26 PM 0
Share

Thanks for the reply!

Lets say I want collisions for the sake of this comment. When such a collision occurs, what process would I need to go through to slow down or stop the rotation/position changes? It seems just setting the position/rotation to an arbitrary value after the collision has happened and is no longer happening does not stop the physics simulation from trying to move the unit around on it's own accord.

avatar image Addyarb · Mar 26, 2015 at 11:34 PM 0
Share

No problem! It can be a bit confusing at first, sorry you're having issues.

Assu$$anonymous$$g you'd like collisions, you can achieve that in a few ways. If you have a building or other static (not moving) object, you can just use two box colliders - one with a trigger enabled that's a bit bigger and one with a trigger disabled so that other objects can't pass through it. This would be enough to trigger a collision.

However, if you are trying to detect collisions on something like a projectile, you are going to want a much more precise and dynamic collision detection. A Rigidbody in this case would give you the ability to effectively detect dynamic (moving object) collision.

Rigidbody comes with some great methods like AddForce, UseGravity, Is$$anonymous$$inematic, etc. However, not everyone wants a game that uses physics they can't control in every situation. This is where you would just use something like Transform.Translate(Vector3.Forward * time.DeltaTime) ins$$anonymous$$d of using Rigidbody.AddForce(100);

While you can achieve some great things when using a Rigidbody, sometimes you just use it for the extra accuracy in collision detection. In this case, you will want to lock down all axis and set your Collision Detection to "Continuous" or "Continuous Dynamic".

$$anonymous$$eep in $$anonymous$$d though, that altering the Transform of the object via code will override the Rigidbody's axis lock system.

avatar image douglasg14b · Mar 26, 2015 at 11:57 PM 0
Share

Very good information, thanks a ton!

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

24 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

Related Questions

Character falls through floor any suggestions? 1 Answer

How to get movable/pushable cubes right? 0 Answers

How to speed up? 3 Answers

Having trouble turning a Transform movement into a Rigidbody force. Code included 1 Answer

Rigidbody Collision? 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