• 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 MigLeader · Aug 23, 2013 at 03:06 PM · collisionphysicsrigidbodyraycastairplane

airplane collision detection problem

$$anonymous$$ their , i am doing a simple top-down view airplane game where u pilot a small airplane then u can land it on the airport , t$$anonymous$$s is where i have the problem bcz the airplane is rigid body here is the scene settings:

1-a flat ground with a box collider(if over t$$anonymous$$s it must crash)

2-a flat rectangle plane (Airport) with a box collider ,if over t$$anonymous$$s it must not crash ever.

3-airplane that is controlled via physics that have box collider that prevents it from falling.

the problem : when landing hard (i want to damage it only) it crashes as if it is over the flat ground , because the colliders intersect with each other and pass each other for a split second.

note:the airport is over the flat ground.

Script:

 #pragma strict
 var $$anonymous$$ts : RaycastHit[];
 var airport : Collider;
 var ground : Collider;
 var height : float;
 
 var boomObject : GameObject;
 var airplaneObject : GameObject;
 var planeWreck : GameObject;
 
 var isLanded : boolean;
 
 
 function OnGUI(){
     if(isLanded == true){
         GUI.Box(Rect(Screen.width / 2 - 50 , 10 , 100 , 25),"Landed!");
     }
 }
 
 function FixedUpdate () {
     $$anonymous$$ts = Physics.RaycastAll (transform.position, -transform.up, 0.5);
     for( var $$anonymous$$t : RaycastHit in $$anonymous$$ts ) {
         if($$anonymous$$t.collider == airport){
             height = transform.position.y - $$anonymous$$t.point.y;  
             if( height <= 0.5){
                 isLanded = true;
                 return;
             }
         }
         if($$anonymous$$t.collider == ground){
             height = transform.position.y - $$anonymous$$t.point.y;
             if( height <= 0.5){
                 Instantiate(boomObject, transform.position, transform.rotation);
                 Instantiate(planeWreck, transform.position, airplaneObject.transform.rotation);
                 Destroy(airplaneObject);
                 Destroy(GetComponent(PlaneControl));
                 return;
             }
         }
     }
 }


please advice and thanks for any help i can get.

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 MigLeader · Aug 23, 2013 at 04:44 PM

ok i have fixed it somehow (work around) , by adding a small timer to the crash script:

 #pragma strict
 var $$anonymous$$ts : RaycastHit[];
 var airport : Collider;
 var ground : Collider;
 var height : float;
 
 var boomObject : GameObject;
 var airplaneObject : GameObject;
 var planeWreck : GameObject;
 
 var isLanded : boolean;
 
 var timeToCrash : float;
 var startTimeToCrash : float;
 
 function Start(){
     timeToCrash = startTimeToCrash;
 }
 
 function OnGUI(){
     if(isLanded == true){
         GUI.Box(Rect(Screen.width / 2 - 50 , 10 , 100 , 25),"Landed!");
     }
 }
 
 function FixedUpdate () {
     $$anonymous$$ts = Physics.RaycastAll (transform.position, -transform.up, 0.5);
     for( var $$anonymous$$t : RaycastHit in $$anonymous$$ts ) {
         if($$anonymous$$t.collider == airport){
             height = transform.position.y - $$anonymous$$t.point.y;  
             if( height <= 0.5){
                 isLanded = true;
                 return;
             }
         }
         if($$anonymous$$t.collider == ground){
             height = transform.position.y - $$anonymous$$t.point.y;
             if( height <= 0.5){
                 isLanded = false;
                 TimetoCrash();
                 
                 //return;
             }
         }
     }
 }
 
 function TimetoCrash(){
     timeToCrash = timeToCrash - 0.01;
     
     if(isLanded == true){
         timeToCrash = startTimeToCrash;
     }
     
     if(timeToCrash <= 0){
         Instantiate(boomObject, transform.position, transform.rotation);
         Instantiate(planeWreck, transform.position, airplaneObject.transform.rotation);
         Destroy(airplaneObject);
         Destroy(GetComponent(PlaneControl));
         timeToCrash = startTimeToCrash;
     }
 }

i have set the (startTimeToCrash) to 0.1;

i know its kind of hackish way to do it but it did it for me.

if there is any better solution for it i wish somebody post it plz, thx.

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.

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

15 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

Related Questions

Raycast doesnt detect object in front of rigidbody (player is stuck on wall) 1 Answer

Nav Mesh Agent won't fall off the platform? 1 Answer

Stop rigidbodies from bouncing 3 Answers

Tossing an object with the correct force at any distance from another so that it collides with the other 1 Answer

Most efficient way to make tracer machingun fire? (raycast or rigidbody) 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