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 Digital-Phantom · Mar 10, 2015 at 04:28 PM · terraintriggerdestroyoncollisionenterterraincollider

Problems destroying object on collision with Terrain

I need to destroy an object when it collides with my terrain. From what I've read in other posts I need to use OnCollisionEnter, not OnTriggerEnter and object cannot have 'is trigger' checked (and there is my problem) the object that needs to be destroyed 'has' to have a trigger as a number of other game mechanics depend on it.

How do I get around this problem

???

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

3 Replies

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

Answer by Digital-Phantom · Mar 12, 2015 at 06:48 AM

Ok its fair to say this problem still perplexes me, even though its now resolved.

There are many conflicting answers to this issue, most of which say Terrain Colliders are not triggers or this/that is no longer valid in Unity 5.

I stripped away all the crap from my project and basically put in the bare essentials on another new build. Created the most basic script and tried again.

 using UnityEngine;
 using System.Collections;
 
 public class DetectCollision : MonoBehaviour
 {
 
     public GameObject playerExplosion;
 
 
     void OnTriggerEnter (Collider other) 
     {
         Debug.Log ("Collision Detected");
 
         if (other.tag == "Player")
         {
             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
             Destroy(other.gameObject);
         }
     }
 }

I made no adjustments to my Terrain collider, simply added this script to the terrain. My player object has a rigidbody attached, a mesh collider, kinematic is unchecked and collision detection is set to discrete.

Everything works fine now. Thought I may have some issues as the player object moves quite quickly, but nothing, its all good (at least for now)

The only issue I did have was that Unity 5 has some weird bug where sometimes the terrain collider is not in alignment with the terrain (so you either explode prematurely or move though the terrain) I believe the UT guys are looking into this so I'm guessing it will be patched soon. As a quick fix just save your project and restart unity, that seems to fix it.

Anyway, hopefully this will help any noobs (myself included there) in case they are having similar issues.

:)

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
avatar image
1

Answer by AndrewToth · Mar 10, 2015 at 07:13 PM

Don`t worry u can use OnTriggerEnter aswell but the ground or the object you want to destroy needs an attached rigidbody otherwise it will not work.

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
avatar image
1

Answer by hexagonius · Mar 10, 2015 at 05:15 PM

Use OnTriggerEnter with isTrigger on the Collider. It will work (just tested that myself)

Comment
Add comment · Show 6 · 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 Digital-Phantom · Mar 10, 2015 at 05:19 PM 0
Share

Terrain Collider doesn't have an 'is trigger' option.

Are you suggesting I remove the terrain collider and use a mesh collider ?

avatar image hexagonius · Mar 10, 2015 at 05:22 PM 1
Share

You said

the object that needs to be destroyed 'has' to have a trigger

set it to isTrigger and have OnTriggerEnter on either it or on the tarrain (depending on who shall react)

avatar image Digital-Phantom · Mar 10, 2015 at 05:39 PM 0
Share

Player object has mesh collider, rigidbody and has 'is trigger' checked (this object has to have a collider/trigger)

Terrain has standard Terrain Collider, a rigidbody (I've tried with and without rigidbody and same result)

I need the player object to be destroyed when it collides with the Terrain/Wall.

 using UnityEngine;
 using System.Collections;
 
 public class CanyonWall : $$anonymous$$onoBehaviour
 {
 
     public GameObject playerExplosion;
     
     void OnTriggerEnter(Collider other)
     {
         if(other.tag == "Terrain")
         {
             Debug.Log("You Crashed");
             Instantiate(playerExplosion, transform.position, transform.rotation);
         }
             Destroy (gameObject);
     }
 }
 

I have a custom tag attached to my Terrain, spelling and capitalisation are correct. I get nothing, not even the Debug message.

???

Oh and I'm using Unity 5

avatar image AndrewToth · Mar 10, 2015 at 07:37 PM 0
Share

Wanted to test it out and got this message.

"TerrainColliders can no longer act as triggers since Unity 5.0", looks like you have to use colliders after all.

avatar image Digital-Phantom · Mar 10, 2015 at 09:03 PM 0
Share

Beginning to think it might even be a glitch in Unity 5. Used all variations of OnTriggerEnter / OnCollisionEnter, different mesh types, 'is trigger' checked and not checked, with and without rigidbody.

Will start again tomorrow, maybe things clearer after some sleep...lol

Show more comments

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

23 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

Related Questions

need trigger + collide 2 Answers

How to create object using onCollisionEnter trigger function ? 1 Answer

How to restrict building on uneven surfaces? 2 Answers

Target touching enemy collision 1 Answer

Player sometimes, only occasionally falls through terrain 2 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