How to find the ground

User avatar
DoctorX
Scavenger
Posts: 49
Joined: 10 Mar 2016, 00:36

How to find the ground

Postby DoctorX » 19 Mar 2017, 17:35

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?

User avatar
Alundaio
S.T.A.L.K.E.R.
Posts: 1368
Joined: 26 May 2012, 22:26

Re: How to find the ground

Postby Alundaio » 19 Mar 2017, 18:02

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
"I have a dream that one day this community will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident; that all mods are created equal."

User avatar
DoctorX
Scavenger
Posts: 49
Joined: 10 Mar 2016, 00:36

Re: How to find the ground

Postby DoctorX » 20 Mar 2017, 20:44

The lvid trick works great. Thanks!


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests