Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: Make appear/disappear/move programatically objects from a scenery ?  (Read 11923 times)

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761

Is it possible to use a javascript file (for instance of a vehicle) to make disappear/appear or displace  objects in a scenery previously placed by the scenery editor ? The idea would be to make appear or disappear or displace objects of the scenery depending on time of day (for instance rush hour) or weather conditions to bring the scenery to life? I guess that if it would be possible to get an "id" of objects inside the editor these could then be used to manipulate the objects from within the javascript, but I could not see any information on something like "id" in the scenery editor. Is there a way to get such info to be shown or retrieved somehow ?
« Last Edit: February 24, 2019, 01:17:20 am by fly77 »
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #1 on: March 04, 2019, 12:25:57 pm »

When hitting a building or a static object (vehicle ) with a tracer from the code below I get indeed an "id" that is a large negative number which seems to identify the building/object in the scene. If I hit a spawned vehicle I get a positive small number as result. Hitting the first spawned vehicle gives hitid=0 and hitting a second spawned vehicle gives hitid=1 etc. How can I use this/these ids to make disappear or move the hit object ? More precisely how can I use the returned id to access the object for instance to remove it with the remove_from_scene() command.

hitid =  $explosions.landed_tracers()[0].hitid;
« Last Edit: March 04, 2019, 02:34:13 pm by fly77 »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #2 on: March 06, 2019, 06:20:10 am »

get_object(id) called on world object will return a reference to the object.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #3 on: March 06, 2019, 08:28:26 am »

Thank you very much for the kind help..will reward it sharing some new mod.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #4 on: March 06, 2019, 12:39:51 pm »

Wow !  It works ! I can now destroy vehicles and buildings ! Opens lots of possibilities ! Even damage to "modular" buildings.  Thanks a lot !! Now I'll have to work a lot  =D =|
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #5 on: April 23, 2019, 03:50:52 pm »

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: [Select]
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;
}

}
« Last Edit: April 23, 2019, 04:39:07 pm by fly77 »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #6 on: April 24, 2019, 02:48:46 am »

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.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #7 on: April 25, 2019, 04:12:07 pm »

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: [Select]
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});
Then i tried to exit and remove myself from scene as follows...

Code: [Select]
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();   
      }
    }

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.
« Last Edit: April 25, 2019, 04:29:21 pm by fly77 »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #8 on: April 26, 2019, 04:22:14 am »

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).
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Make appear/disappear/move programatically objects from a scenery ?
« Reply #9 on: April 26, 2019, 01:41:37 pm »

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: [Select]

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();   
      }
    }
     
« Last Edit: April 26, 2019, 06:05:31 pm by fly77 »
Logged