hi 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 , this 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 this it must crash)
2-a flat rectangle plane (Airport) with a box collider ,if over this 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 hits : 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 () {
hits = Physics.RaycastAll (transform.position, -transform.up, 0.5);
for( var hit : RaycastHit in hits ) {
if(hit.collider == airport){
height = transform.position.y - hit.point.y;
if( height <= 0.5){
isLanded = true;
return;
}
}
if(hit.collider == ground){
height = transform.position.y - hit.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.