• 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 blackmamba21 · Mar 09, 2012 at 08:46 PM · collisioncollider

collision detection

Hi so i have an object and when it hit the wall I want to disable the renderer, reposition it at it original place and wait 2 secs before moving it again. If I reposition it before waiting, the collision with the wall are not detected anymore after the first collision. However if I reposition it after waiting theres no problem. But I need to replace it BEFORE. I don't think theres a problem with the yield cuz its working with the reposition after. Direction is my movement vector. I debug with collider.enabled and its always true as it should be Thanks alot guys and sorry for bad english.

     void Show(bool state){
     int i;
     
     renderer.enabled = state;
     isColliderEnable = state;
 }
 
 IEnumerator Respawn(){
     direction = new Vector3(0,1,0);
     Show(false);
     transform.position = startPosition;    //COLLISION NOT DETECTED ANYMORE AFTER 
     yield return new WaitForSeconds(2.5f);
             //transform.position = startPosition; NO PROBLEM IF THIS LINE IS HERE
     Show (true);
     direction = transform.forward * Time.deltaTime * speed;
 }
 
 void OnTriggerEnter (Collider col) {
     if(isColliderEnable){
         if(col.name == "Wall"){
             StartCoroutine(Respawn());
         }
     }
 }
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 tingham · Mar 10, 2012 at 03:37 AM 1
Share

Why are you wanting to reuse this particular game object? Why not simply instantiate a new one and let the exhausted one be destroyed ins$$anonymous$$d?

avatar image blackmamba21 · Mar 10, 2012 at 11:09 AM 0
Share

For memory allocation. People always taught me to reuse the object ins$$anonymous$$d of destroying and instantiating. If I port my game to ios I think it could be an issue. Anyway I manage to do it and I don't know why with the same code without calling my method show:

 IEnumerator Respawn(){
     direction = new Vector3(0,0,0);
     renderer.enabled = false;
     isColliderEnable = false;
     transform.position = startPosition;
     yield return new WaitForSeconds(2.5f);
     
     renderer.enabled = true;
     direction = Vector3.forward * Time.deltaTime * speed ;
     isColliderEnable = true;
 }
 
 void OnTriggerEnter (Collider col) {
     if(isColliderEnable){
         if(col.name == "Wall"){
             StartCoroutine(Respawn());

         }
 }

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Player detecting collision when crouching 1 Answer

What's wrong with OnCollisionEnter? 2 Answers

Change Boolean with collision problem 2 Answers

Trying to check area for game objects that collide with spawnpoints, then spawn an item where ever there is not a collision 0 Answers

Compound collider does not trigger the parent 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