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 kebrus · Nov 26, 2012 at 04:19 PM · collisioncollidertrigger

Instantiate a collider already colliding with an object not working

Hi once again.

I'm trying to create some sort of melee attack collision detection. I thought it would be simple and i only had to instantiate a collider, check for some collision and be delete it afterwards. I'm using OnTriggerStay but sometimes the collider is created already touching something but if the object which is colliding with is not moving the trigger never happens...

what i'm doing wrong here? is there any simpler way of achieving what i want?

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

2 Replies

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

Answer by thaiscorpion · Nov 26, 2012 at 05:27 PM

Is there a reason you are creating and destroying the trigger? It might be better to maintain it and check if a enemy is inside the trigger when you attack. You could make a simple Bool, isInRange, for each enemy and on trigger enter change to true and on leave change to false, then you only have to check if the enemys isInRange variable and done.

Hope this helped.

Comment
Add comment · Show 4 · 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 kebrus · Nov 26, 2012 at 08:06 PM 0
Share

the reason i'm destroying it is because i don't really need it after the collision is detected and the attack handled, still thats not the problem, the problem is, even if i don't destroy it the triggers never detects the collision with the enemy if/when the enemy is not moving, the collider borns colliding with the enemy and if this enemy doesn't move the collider never triggers anything

avatar image thaiscorpion · Nov 27, 2012 at 10:12 PM 0
Share

Seems like my answer is just what you want then, dont destroy it so it is already instantiated when you need it just use it to check if an enemy is inside it or not.

avatar image kebrus · Nov 27, 2012 at 11:07 PM 0
Share

uhm, that might be a fine solution for me actually, but i would still like to know how why the trigger is not triggered when this case happens, for now i guess your solution might be ideal

avatar image thaiscorpion · Nov 28, 2012 at 06:08 PM 1
Share

the reason it doesnt trigger is because the detection is only calculated when the object moves. Or if you using on enter and leave if its already inside it wont set of that trigger. Once the object moves it executes the detection code and then realises that it has to trigger the event.

avatar image
1

Answer by WillB · May 02, 2013 at 04:34 PM

If anyone else is reading this, thaiscorpion's last comment is correct.

I was instantiating a large BoxCollider (that isTrigger) in front of my player that calls functions on all colliders inside of it, then destroys itself after WaitForSeconds(0.1). It wasn't working, until I added a kinematic rigidbody (lol?) to the instantiated BoxCollider.

Took 3 hours to figure that out; hope I saved you some time. :)

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 gnumb · Nov 09, 2014 at 03:09 AM 0
Share

You saved me some time! :)

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

12 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

Related Questions

Using shadows as Triggers? 1 Answer

How to restart scene with trigger? 1 Answer

Collider won't collide with a trigger 3 Answers

How to design an Archer Board Scoring System 1 Answer

Fire Collision detection 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