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 Jeroenvw · Jun 06, 2016 at 07:10 AM · movementphysicsrigidbodycharactercontrollerjoint

How to let a GameObject generate force but not be affected by certain forces?

tl;dr Without using a kinematic Rigidbody, how do I enable some GameObject A to move some GameObject B, but disable B to move A? (Looking for a "force diode".)

I am making a 2D local co-op game where players work together to move objects around or rotate them. My current solution to achieve this is as follows.

The objects have one ore more 'attachment points'; when a player is on top of such an attachment point, he can attach himself to the object, meaning the attachment point will not move relative to the player nor the object, but rotation is still possible. To paint a clear picture: it's like hammering a nail through the attachment point on the object, through the player as well.

I do this by, upon attaching, adding a HingeJoint between the Rigidbody of the object (which is, in terms of GameObjects, a parent of the attachment point) and the player. A HingeJoint is a constraint between two Rigidbodies, so my player GameObject must have a Rigidbody as well.

However, because my player GameObjects now have a Rigidbody, they are affected by certain forces I do not want them to be affected by. For example, when two players attach themselves to the same object and only one starts moving, the other one will move as well (involuntarily) because their Rigidbodies are both constrained to the same Rigidbody, being the Rigidbody of the object they attached themselves to.

What I want is that players cannot be moved unless it is voluntarily (by user input) or by collision response (players shouldn't be able to move through certain GameObjects, like walls). This is exactly what a CharacterController can provide for me, but because of the way I attach players to objects I also need a Rigidbody. Making players kinematic and somehow make them not go through walls would not solve the problem as having two kinematic Rigidbodies constrained to the same Rigidbody with Joints causes the Joints to simply explode.

On top of that, entities other than players are supposed to be able to attach to objects as well, using the same attachment points. Think of the player attaching himself to a key, carrying it to a keyhole, where the keyhole then attaches itself to the key. The floor attaches itself to one end of a long object, the other end has an attachment point for the player to work with; a lever. I would really like to maintain a generic solution such that the endless possibilities of this attaching system will remain. Currently I do this by having an Attacher interface make attachment requests to the AttachmentPointController component of the attachment points. Via this interface the attachment point asks where the Joint should be anchored on the Rigidbody of the Attacher. Anything with a Rigidbody can then start attaching itself to objects by simply implementing the Attacher interface.

This attachment point using a Joint and an interface approach seems like the way to go, except for the fact that players are involuntarily moved because of these Joints. Is there any way to keep the Rigidbody on players yet not make them move involuntarily? Perhaps if I could somehow disable players to be affected by Joint forces, but still enable them to generate Joint forces?

Ideally I'd find a solution that allows me to keep using Rigidbodies for my players, but if there is no other way to stop my players from moving involuntarily I am willing to switch to CharacterControllers, meaning I will likely also have to abandon my point-joint-interface approach. Are there any CharacterController solutions that still allow me to have a generic solution to let entities attach themselves to objects?

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Click to move a character in a terrain 1 Answer

Turning a rigidbody controller into a character controller (almost) 1 Answer

Unity Physics On Input Issue? 0 Answers

Strange Rigidbody Behavior 0 Answers

Character Controller Pushes Car With Wheel Colliders? 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