Page 1 of 1

How to find the ground

Posted: 19 Mar 2017, 17:35
by DoctorX
Say I want to spawn an object on the ground at a random location by doing the following:

Code: Select all

local smart = SIMBOARD.smarts_by_names["some_smart_terrain"]
local pos_x = smart.position.x + math.random( 20 )
local pos_y = ?
local pos_z = smart.position.z + math.random( 20 )

local pos = vector( ):set( pos_x, pos_y, pos_z )

alife( ):create( "some_object", pos, smart.m_level_vertex_id, smart.m_game_vertex_id )


What is the best way to find the y-component (elevation) of the ground at the chosen x,z (lat, long) location?

Re: How to find the ground

Posted: 19 Mar 2017, 18:02
by Alundaio
For your example you could do something like this:

Code: Select all

local lvid = level.vertex_id(pos)
pos = level.vertex_position(lvid)


lvid value of 4294967295 is invalid, so might want to check for that.

You can also use level.vertex_in_direction(pos,dir,radius) to generated random positions in a radius from a position. But keep in mind that only moves along valid AI Map, if there is an obstacle it will stop.

Example, say _ is the AI Map and at 10m there is an obstacle [] and I use level.vertex_in_direction(pos,dir,30). It's going to return the lvid before the obstacle.

0m----------------10m----------------------30m
_ _ _ _ _ _ _ _ _ [ ] _ _ _ _ _ _ _ _ _ _ _ _
------------------^--- returned

Re: How to find the ground

Posted: 20 Mar 2017, 20:44
by DoctorX
The lvid trick works great. Thanks!