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 Nightwhistle · Dec 28, 2015 at 03:21 PM · collider2dcollision2d

Collision happens, code executes but not working all the time

Recording of problem (the green brick) https://www.youtube.com/watch?v=0ftSmXsN-4A&feature=youtu.be

I have (RigidBody2D) ball hitting (RigidBody2D) bricks. Both have Collider2D on them. Bricks are instantiated from prefab at start, all have same "destroy" script that's hiding them and turning colliders off since at some point I want to re-enable them again.

When ball hits them, they act as they should: they hide and keep moving. However, sometimes (more like 1 in 20 hits) brick just fails to hide. It does collide but it starts moving as rigid object instead. I tried setting it on kinematic on hit, same issue.

What I tried:

  • Both bricks and ball collision detection on continuous and descrete

  • Both bricks and ball Interpolate to interpolate / extrapolate / none

  • Bricks move with Translate() / RigidBody.AddForce() / basic transform to side

  • Tried to actually Object.destroy() bricks on collision, same thing happens

Not sure what scripts I need to put here, so basically:


Bricks move:

transform.Translate(Vector3.right * speed * Time.deltaTime);

Collision detection on bricks:

edit: for some reason collision script broke and is showing some weird symbols. I'm not home to repost it till tomorrow.

Even on times when brick is not destroyed but actually bounced back, all Debug.Log() calls show right logs: the same brick is false to renderer, false to collider.enabled and isKinematic is true so it actually executes collider script every time.

Thanks.

Edit: Video was private instead of unlisted. Fixed now.

Comment
Add comment · Show 2
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 wibble82 · Dec 28, 2015 at 04:39 PM 1
Share

your video is private!

avatar image Nightwhistle wibble82 · Dec 28, 2015 at 08:58 PM 0
Share

I guess i miss clicked private ins$$anonymous$$d of unlisted. Its fixed now.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MelvMay · Dec 28, 2015 at 05:00 PM

If you're going to disable/enable then by far the fastest way is to set Rigidbody2D.simulated to false. This tells the simulation to ignore the rigid-body, colliders, joints (etc) and doesn't require destroying/recreating stuff. As I said, very fast.

In terms of why your bricks are not 'hiding'; I'm not sure. As you said, you've verified that the script is called so it seems like it's nothing to do with the actual physics system.

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 Nightwhistle · Dec 28, 2015 at 05:26 PM 0
Share

If bricks are set kinematic all the time everything works perfectly. Thing is i want to add some bomb blocks that will apply some force when destroyed to all other bricks around and when I use them as non-kinematic they start to act weird and not hide/destroy.

I will try to set simulated to false, but I'm not home till tomorrow to give feedback.

avatar image Nightwhistle · Dec 28, 2015 at 08:55 PM 0
Share

I was pointed my video was private. Can you please watch it to see what's going on. I changed it to unlisted. Thank you.

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

Collider2D.GetContacts(List() contacts) works with OnColliderEnter2D but not with OnTriggerEnter2D 1 Answer

OnTriggerEnter2D and ladder won't be compatible 2 Answers

Disable click action when collision 1 Answer

Edge Collider issue 1 Answer

How do I set an object's velocity to the velocity of an object that collided with it? 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