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 Fraggle222 · Nov 26, 2012 at 06:57 PM · rigidbodycolliderrigidbody.addforce

Why can't I use RigidBody.AddForce and also have a collider?

If I have a game object that is a rigidbody, and I have a script to control the rigidbody , everything is fine. However if I add a collider to that gameobject, then everything goes crazy. Literally the control that worked before in the script no longer works as before. Unpredictable movement results. Disable the collider and back to normal.

I've tried this a few different times, different scripts, etc so I don't think it is code related exactly, but perhaps a just the way Unity works. Is that true? Not a Unity bug?

Yes I know I can use a character controller or directly move or manipulate transforms. But in some cases using AddForce or AddForceAtPoint is the best way to simulate something (like an airplane). I also know I can use Raycasting as an alternative to detecting collisions. But is there anyway to get colliders to work while also using AddForce in scripts?

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 kebrus · Nov 26, 2012 at 08:18 PM 0
Share

if you are adding the collider only now i'm gonna assume you are your rigidbody isn't actually reacting to anything besides your control script, so if you are adding a collider, make it a trigger so it doesn't react to anything besides being a trigger, if you still need to add real collision make sure your rigidbody is setup properly, before adding a collider your gameobject is kinda like a ghost, because colliders are what gives it form

i'm guessing you did your control script without ever considering colliders and you might have something there that only reacts with your gameobject when it has form, or in other words, a collider

so yeah, it's either a setup problem on the rigidbody or collider, or your script, if you need more help, we need to see your script

avatar image Fraggle222 · Nov 26, 2012 at 08:34 PM 0
Share

@kerbrus: Only thing my script does is apply forces via rigidbody.AddForceAtPoint calls. Note also that "iPhone 3D Program$$anonymous$$g" by Alessi says: "The problem with adding a box collider to the airplane is that it changes the physics of the flight model". So maybe this is something that only becomes obvious for flying games, and is not so obvious on the ground. I will try to post a simplified script that exhibits the problem.

avatar image Eric5h5 · Nov 26, 2012 at 09:42 PM 1
Share

A collider can't change the physics model in any way, so the book is wrong. The only things that affect the physics model are mass (more mass = more force necessary when using AddForce, unless of course you use Force$$anonymous$$ode.Acceleration or Force$$anonymous$$ode.VelocityChange) and drag (which is just a number and does not take the shape into account at all, so a box flies equally as well as a needle).

If you want a realistic physics model for flight, you will need to write your own. The built-in engine is good for simple things but can't emulate things like air flow and so on. If you're not ai$$anonymous$$g for realism and just need basic game physics, then the built-in engine is fine.

avatar image kebrus · Nov 26, 2012 at 09:45 PM 0
Share

the only way i see colliders affecting the physics is if they are somehow colliding with something, start a fresh project and see for yourself, put something flying with only a collider, rigidoby and some AddForce on it and you'll see it will fly as intended, what are you parameters for your rigidbody? do you have any global variable like, i dunno, wind or something?

avatar image Fraggle222 · Nov 26, 2012 at 10:22 PM 0
Share

I think you are missing it: Below is likely the answer. Note that Eric5h5 was probably on to something by mentioning Drag which I am using. from http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-inertiaTensorRotation.html "If you don't set intertia tensor rotation from a script it will be calculated automatically from all colliders attached to the rigidbody."

3 Replies

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

Answer by Bunny83 · Nov 26, 2012 at 11:01 PM

It's actually the other way round. A Rigidbody without a collider does act strange because a Rigidbody always needs a collider to work correctly. Unity will determine some values from the attached collider(s) as you figured out:

  • inertiaTensor

  • inertiaTensorRotation

  • centerOfMass

Keep in mind that a rigidbody can have multiple colliders which are used as one compound collider.

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 Fraggle222 · Nov 27, 2012 at 02:33 PM 0
Share

Bunny83->Thanks. The other commenters were making me think I was crazy.

avatar image
2

Answer by Fraggle222 · Nov 26, 2012 at 10:23 PM

Answering my own question here, I believe it has to do with this:

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-inertiaTensorRotation.html "If you don't set intertia tensor rotation from a script it will be calculated automatically from all colliders attached to the rigidbody."

This was referenced form a similar question in Forums: http://forum.unity3d.com/threads/158886-Why-Does-Changing-a-Collider-Affect-Rigid-Body-Physics

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 Fraggle222 · Nov 26, 2012 at 10:24 PM 0
Share

I selected Bunny83's answer ins$$anonymous$$d of my own.

avatar image
0

Answer by Eric5h5 · Nov 26, 2012 at 08:01 PM

Adding a collider doesn't change rigidbody behavior, aside of course from enabling collisions or triggers. There's no bug; it's definitely something in your code or your setup. Also you can't use raycasting to detect collisions without colliders--you need something for the rays to hit, and it's not really an alternative in many cases anyway. Without knowing anything about what you're doing, my only suggestion is that if you're using parents/children, make sure that the children do not have rigidbodies. In this case, having children with colliders makes a single compound collider, so only the parent should have a rigidbody.

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 Fraggle222 · Nov 26, 2012 at 08:35 PM 0
Share

I think this is incorrect ("adding a collider doesn't change..."). See my comment above regarding the quote from the book. So I'm not the only one who has had this issue. Colliders definitely affect behavior of rigidbodys when you are applying forces to them.

Also regarding Raycasting. I can use raycasting from an object that does not have a collider and have it Hit objects that do have colliders.

avatar image Eric5h5 · Nov 26, 2012 at 09:38 PM 0
Share

It's not incorrect; the book is wrong. There is no physics model built into Unity that takes colliders into account.

avatar image Fraggle222 · Nov 26, 2012 at 10:22 PM 0
Share

Found this: http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-inertiaTensorRotation.html "If you don't set intertia tensor rotation from a script it will be calculated automatically from all colliders attached to the rigidbody."

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

13 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

Related Questions

Avoid one gameObject skin in another gameObject 2 Answers

how to Apply Gravity at Run time ..????????? 2 Answers

OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer

Does collider size affect performance? 1 Answer

My Objects are falling through the floor.. 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