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
1
Question by rayben · Mar 03, 2015 at 09:08 AM · gameobjectrigidbody2dphysics2d

Is it possible for two game objects to reference the same rigid body?

I'm making a simple 2d space game. If the space ship flies off the screen to the left it should appear on the right. So think of the screen as a flattened out sphere.

The way I achieve this is by making a clone of the ship on the opposite side when it starts to leave the screen. When the clone is fully "inside" the screen again I teleport the ship to the clone position and Destroy() the clone (as suggested by this guy).

It works well, but sometimes when a clone exists and it (or the ship) is hit by a rock floating by, the ship and the clone fall out of sync. What I would like is if the clone is hit by a rock, making it drift in a different direction and have it's rotation altered, the same forces should be applied to the ship (and vice versa).

I tried setting the rigidbody2D of the clone to the same as the ships but the property is not setable (GameObject.rigidbody2D). I also thought about writing something in the OnCollisionEnter() to set the velocity and angularvelocity of the ship manually. But I don't know if the physics have been applied at that point and I can't find a clear answer.

Has anyone done anything like this before?

Comment
Add comment · Show 3
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 meat5000 ♦ · Mar 03, 2015 at 03:19 AM 0
Share

You can use GetComponent to access any component or script on another object.

avatar image VipHaLongPro · Mar 03, 2015 at 09:49 AM 0
Share

I can understand your problem but even referencing the same Rigidbody was possible, it still could not solve your problem. You may have to synchronize the 2 via the Update() message by updating the transform info of this one based on the other. However this works only in some limited cases. Generally your problem is something very complicated I think (unless you don't use Rigidbody at all but then you have to manually update the objects collision yourself).

avatar image rayben · Mar 03, 2015 at 08:23 PM 0
Share

I don't see why having the clones reference the same rigidbody as the original ship wouldn't solve it. I did think about using Update() or perhaps better yet, FixedUpdate(). But I don't think the physics have been calculated yet at the time the function is called. But perhaps it's no a big deal if the rigidbody of the other is updated one physics step later. I'll try it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by _MGB_ · Mar 03, 2015 at 10:53 AM

You could create your clone, deactivate its rigid body and slave its position to the original ship. Then if/when your original is removed, activate the rigid body on the clone.

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 rayben · Mar 03, 2015 at 08:16 PM 0
Share

Actually, as far as the player is concerned there is only one ship. If the clone is hit by a rock it must also react to it and copy the reaction to the original ship. So my question is basically this: how do I copy physics based reactions between game objects with rigid bodies?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to rotate a Rigidbody2D faster than 4500 (degrees/s)? 0 Answers

Strange Circle collider 2D physics behaviour 1 Answer

Reset Rigidbody2D rotation after collision 2 Answers

How can I hide physics? 1 Answer

Angular velocity not affecting Rigidbody2D 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