User mods, screenshots & videos > Scenery

Make appear/disappear/move programatically objects from a scenery ?

<< < (2/2)

fly77:
I am trying to make disappear a plane when it crashes into the ground.
I tried the code below and while the plane disappears a house appears in its place but looking in the editor it is still identified as the plane...indeed it is a house that continues to move ..it is effectively the plane in the clothes of a house. I am driving a house ::).  Sometimes the plane disapperas as wanted but I still can hear the pane noise and indeed in the editor the plane is still there, just invisible. In both cases control is not returned to ufo mode.  Also geom.set_visible(false) makes the plane invisible but it still is heard and control is still attached to the invisible plane. I tried geom.exit() or this.exit() to get back to ufo mode but in both cases I get error...has no method  exit()

How to effectively remove the plane and return control to ufo mode ?


--- Code: ---function initialize(reload){
    geom = this.get_geomob(0);
}

function update_frame(dt){

if ((!crashed)&&((this.elevation_above_terrain({x:0,y:0,z:0},100000, propeller)<5))   ){
  geom.remove_from_scene();
  crashed=true;
}

}
--- End code ---

cameni:
That house swap is likely a bug in this version.

Normally one would have to remove aircraft object from scene, not just its geomob. However, aircraft physics interface that's controlled by the script can't really remove the object from the scene, it doesn't have a method for that and it likely won't have one because physics/behavior script should not be deciding when to remove objects from scene.

There's a hackish way to do it via aircraft control interface, but you'd first need to obtain it via the world interface, like raycasting itself.

Maybe something different should be used. Aircraft physics script should not decide on removing the object from the scene, but it may be responsible for handling what happens on damage or upon meeting the ground forcibly.
For example, there could be a hidden damaged mesh in the pkg, and you'd swap visibility. Or you could actually load a new geomob and use set_visibility.

fly77:
Thanks for the answer. By chance I was tinkering with  the   "world.find_object_mesh "  command I saw in one of the default models...i don't remember which one...
Is this the command for raytracing ? As far as I could understand it takes as arguments (ECEF start position  , ECEF search range end position) ......or does it use model space coordinates ?

Raytracing onto itself ? Does it mean that I need to set a certain direction variable "direc" I guess in ECEF space (for instance the gravity normal to earth surface in ECEF coordinates)  and an ECEF startposition ?  In case I choose for instance  the gravity normal as direction the start position could be  a point above my vehicles/boat/plane ECEF position and then I do a raytracing down along the gravity normal.   For instance starting 3 units (meters) above myself and searching in a range of 10 m downwards I should get myself's object reference ..something like this ?:


--- Code: ---var obj = world.find_object_mesh( {x: pos.x + direc.x*3, y: pos.y + direc.y*3, z:pos.z + direc.z * 3}, {x: pos.x - direc.x*10, y: pos.y - direc.y*10, z:pos.z - direc.z * 10});
--- End code ---

Then i tried to exit and remove myself from scene as follows...


--- Code: ---if(obj && obj.$ret) {
      if(this.geom.get_inst_id() == obj.$ret.get_geomob(0).get_inst_id())
      {
         obj.$ret.exit();  
          obj.$ret.remove_from_scene();   
      }
    }

--- End code ---

I tried something like this first using the camera position and camera direction and it worked fine but depended on the camera looking in the right direction or something else I could'nt understand . ..at some of the firts person viewpoints I managed to "delete myself" ...so it is indeed possible but I wanted to do something that doesn't depend on the camera view.
 ..that's why I then tried with the gravity normal but I could not get it to work in this case till now.

cameni:
One thing, it will fail to hit when you are inside the collision shape itself, you need to move away a bit (just like you can't enter vehicles when you are inside).

fly77:
Thanks ! I now can delete my crashed plane reliably  ! ...Instead of using the gravity normal following your hint I now tried the direction that one normally exits form a vehicle (exit is normally to the left) using model coordinate offsets  to define the ECEF direction as below.

 
--- Code: ---
var pos = geom.get_world_pos_offset({x:-10,y:-5,z:0},propeller);
var pos2=  geom.get_world_pos_offset({x:-9,y:-5,z:0},propeller);
var direc = {x: pos2.x-pos.x, y: pos2.y-pos.y, z: pos2.z-pos.z};
           
var obj = ot_world.find_object_mesh( pos, {x: pos.x +direc.x*20, y: pos.y + direc.y*20, z:pos.z + direc.z * 20});


     if(obj && obj.$ret) {
      if(geom.get_inst_id() == obj.$ret.get_geomob(0).get_inst_id())
      {
         obj.$ret.exit();  
         obj.$ret.remove_from_scene();   
      }
    }
--- End code ---
     

Navigation

[0] Message Index

[*] Previous page

Go to full version