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 Sparen-of-Iria · May 09, 2018 at 03:48 AM · collisionrigidbody2doncollisionenterdynamickinematic

How do I prevent a Kinematic Rigidbody2D from moving a Dynamic Rigidbody2D on Collision?

Hi. I'm working on a 2D game in Unity 2017.3 (macOS) and have a problem with RigidBody2D collision. For context, I have bullet GameObjects that are interacting with GameObjects with Dynamic RigidBodies in a less-than-optimal fashion for what is required for our project.

These bullet GameObjects have kinematic RigidBodies and do the following OnCollisionEnter2D:

If they collide with other rigid bodies with the same tag or collide with the enemy that spawned them, they disable collision with those GameObjects with Physics2D.IgnoreCollision so that they will not re-collide with them in the future.
If they collide with the player, they run a bunch of code and then destroy themselves with Destroy(this.gameObject, 0f);
If they collide with anything else (such as walls), they destroy themselves with Destroy(this.gameObject, 0f);

Now, my problem is that these GameObjects, which have a kinematic RigidBody, push the player on collision - right before deletion. They also push the enemy that spawned them if the enemy does not explicitly disable collision with the spawned object immediately after creation.

I need OnCollisionEnter2D to still trigger when the GameObject collides with something, as there are various cases that need to be taken into consideration within the codebase. I need the GameObject's RigidBody to be kinematic, as using dynamic results in unwanted behavior. The GameObject's RigidBody is kinematic and should not have any mass to push dynamic RigidBodies with (yet it does?). But at the same time, I do not want the object to push other objects that contain Dynamic RigidBodies on collision.

I am using Use Full Kinematic Contacts, and the GameObject has an attached Circle Collider 2D that is not set to trigger (setting to trigger results in OnCollisionEnter2D never being called). If anyone could provide advice on how to rectify the problem, either through code or via the settings in the prefab via the Inspector, that would be very helpful.

Thank you very much.

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

1 Reply

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

Answer by TanselAltinel · May 09, 2018 at 10:52 AM

There are possible solutions to this issue.

One of them may be that you can use Trigger instead of Collider, which will not push any collider aside.

Second could be that you can decrease mass and friction of bullet and increase mass and friction of enemy/player objects, such that bullet cannot push them due to physics.

Comment
Add comment · Show 2 · 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 Sparen-of-Iria · May 09, 2018 at 03:20 PM 0
Share

Thank you. Using IsTrigger with OnTriggerEnter2D works the way I want it to.

avatar image TanselAltinel Sparen-of-Iria · May 09, 2018 at 03:41 PM 0
Share

You're welcome. In my game I want melee weapons and bullets to move enemies so I use non-trigger colliders, but for everything else it's better to have triggers.

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

130 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

Related Questions

How to move multiple dynamic gameobjects with one moving platform which is controlled by the player 0 Answers

How to make kinematic rigidbody react to some collisions 6 Answers

Switching from kinematic to dynamic without stutter 0 Answers

How do I make a rigidbody2d that doesn't do anything on collision? 1 Answer

How to perform grasp action on a cloth? 3 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