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 Alex! · Jun 08, 2013 at 02:46 AM · rigidbodycolliderontriggerenteris trigger

Box collider doesn't work when same size as mesh.

The general Effect I'm creating here is a cube that splits into smaller cubes when destroyed that can then be picked up by being run into by the character controller, with each one adding to the 'score'. The sequence I'm using is this:

Main block (1x1x1) destroyed. - Prefab of a 2x2x2 arrangement of 8 block 'fragments' (0.5x0.5x0.5 cubes) instantiated. - Smaller cubes are given a random Vector3 force when created so they 'explode' out.

The way the prefab of the smaller cube arrangement is done is using an empty as a parent which is the GameObject that is instantiated:

BlockFragments (Empty - just the parent for instantiation) - BlockFragment 1 (Cube) - BlockFragmentCollider (Empty) - BlockFragment 2 (Cube) - BlockFragmentCollider (Empty)

And so on with 8 fragments.

The parent has a simple script to remove it if all the children have been removed (picked up).

The fragments have a script giving them a random Vector3 force, and removing them when their child is removed.

The collider empty has a script that removes it when it collides with the player (OnTriggerEnter) and some code to add to the 'score'.


Each BlockFragment cube has a box collider and a rigidbody. The BlockFragmentCollider then has its own box collider and rigidbody, with Is Trigger and Is Kinematic enabled as enabling Is Trigger on the actual cube makes it fall through the floor.

The problem I'm having is that, when the box collider on the collider object is the same size as its parent mesh, it doesn't activate the OnTriggerEnter whatever I do when it collides with the character controller. However, when the collider is 2x the size of the mesh, the whole thing works fine and as planned.

Does anyone have any idea why this is happening, and what I could do to get it working with a collider the same size as the actual cube fragment mesh as having it larger throws up other problems and causes issues with raycasting.

Thanks in advance for any assistance.

Comment
Add comment · Show 4
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 Owen-Reynolds · Jun 08, 2013 at 03:45 AM 0
Share

So each $$anonymous$$i-block has a collider and a trigger, both the exact same size? Seems overly complicated. Is there a reason not to have just a collider?

avatar image Alex! · Jun 08, 2013 at 03:51 AM 0
Share

I played around for a while trying to get it to work like that, but when I set the $$anonymous$$i-block's collider to Is Trigger, it just made the blocks fall through the floor. The problem is that I can't enable Is $$anonymous$$inematic on the rigidbody to stop this as I need the forces to be applied so it 'explodes' out - enabling Is $$anonymous$$inematic results in it not moving at all from what I can see - or at least, not being affected by forces.

avatar image Owen-Reynolds · Jun 08, 2013 at 03:05 PM 0
Share

But, do you really need a trigger at all? OnCollisionEnter will usually check for a hit just as well as OnTriggerEnter.

avatar image Alex! · Jun 08, 2013 at 03:18 PM 0
Share

Ah, I didnt want to use collisionenter as I'm using a Character Controller so have to use OnControllerColliderHit and do it controller-side, but I guess it saves a lot of unneeded extra colliders and rigidbodies + scripts and I just got it working fine that way. Thanks for the help, I appreciate it!

1 Reply

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

Answer by aldonaletto · Jun 08, 2013 at 04:11 PM

If the small blocks are pickup items, you really should use triggers bigger than their colliders. The CharacterController must penetrate a trigger a little (not so little) in order to generate an OnTriggerEnter event: if the trigger isn't big enough, the character will be stopped at the internal collider and no trigger events will occur.

In order to avoid raycast problems, you can clear the checkbox Raycast Hit Triggers in the Physics Manager. Another possibility is to place the small blocks in a specific layer and do the raycasts with a suitable mask - if the cubes are in layer 8, for instance, use the negated mask ~1<<8 to check all layers but layer 8.

Anyway, if you want to use OnCollision events, be aware that they only are reported when the rigidbody hits the CharacterController, not the other way around. On the other hand, OnControllerColliderHit does the opposite: it's reported only when the character hits a collider. OnCollisionEnter may be used when the blocks are moving, but will fail if they are at rest.

Comment
Add comment · 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

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

16 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

Related Questions

100 OnTriggerEnter Or Tags each player too much? 3 Answers

OnTriggerEnter works, OnTriggerExit doesn't 3 Answers

Rigidbody + Multiple Trigger Colliders - OnTriggerEnter - Get which Collider triggered the event issue 1 Answer

OnTriggerEnter/Exit called unexpectedly 2 Answers

How to use OnTriggerEnter? (JS) 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