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 jonmar2348 · Aug 23, 2011 at 10:05 PM · collisiongameobjectterrainairplane

Airplane - Collision With Terrain Problem

I wrote a script for my plane to be destroyed and explode when it collides with the terrain but it doesn't work. The plane has a rigidbody, and I tested out with the Is Trigger option off and on. Can anyone help me out? Thanks.

var explosion : ParticleEmitter;

function OnCollisionEnter (collide : Collision)

{

 if(collide.gameObject.tag == "Terrain")

 {

     Destroy(gameObject.Find("F-16"));

     Instantiate(explosion, transform.position, Quaternion.identity);    

 }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Aug 23, 2011 at 11:37 PM

Is this script attached to the airplane? If that's true, use Destroy(gameObject); since this will "suicide" the script owner - the airplane, in this case. The way you did it should work too, but you should avoid GameObject.Find because it's too slow, and a common source of errors too.
Anyway, a possible reason for this to fail is the terrain tag: the terrain is untagged unless you explicitly tag it - and you must create the tag Terrain, since it's not included in the default tag list.
Check the terrain tag, and if it's ok place a debug line before the if - something like print("Hit something"); - to refine the bug search.

Comment
Add comment · Show 5 · 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 jonmar2348 · Aug 24, 2011 at 07:20 PM 0
Share

I tried the method and the message didn't pop-up when the plane collided into the terrain.

avatar image aldonaletto · Aug 24, 2011 at 09:18 PM 0
Share

And what about the terrain? Was it tagged "Terrain"? And is this script attached to the F-16 object?

avatar image jonmar2348 · Aug 24, 2011 at 10:15 PM 0
Share

Yes, I tagged the terrain and attached the script to the F-16. I still get the same result.

avatar image aldonaletto · Aug 24, 2011 at 11:07 PM 0
Share

It should work. I tested this same script with a block named F-16 and the changes I've suggested, and the block was destroyed as soon as it touched the terrain.
Are you using the Unity terrain? Click the terrain and verify at the Inspector if it has the Terrain Collider component, and be sure IsTrigger isn't checked.

avatar image jonmar2348 · Aug 25, 2011 at 06:19 PM 0
Share

I made sure it wasn't checked.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Gameobject collision with Terrain C# 4 Answers

How do I stop an immediate collision with all objects from ocuring at the entry of game mode? 0 Answers

changing color on collision -1 Answers

Physics.OverlapSphere() not working after using pool of objects 0 Answers

Generate collision mesh from 2d texture? 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