preview
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
preview [2020/04/22 11:50] – vjraymon | preview [2021/10/15 10:43] (current) – removed maxime | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Custom component: how to compute ground or water elevation ====== | ||
- | Since 1.5, Foundation allows to mod Custom component and links it to a fbx (see Exemple02) | ||
- | |||
- | The following LUA code computes and returns the global Y elevation of water from a global position: | ||
- | |||
- | function MY_CUSTOM_COMPONENT: | ||
- | local raycastResult = {} | ||
- | |||
- | -- Raycast from the _globalPosition + 1000 | ||
- | -- to _globalPosition - 1000 | ||
- | -- only on objects with a WATER flag | ||
- | local FromPosition = { _globalPosition[1], | ||
- | local ToPosition = { _globalPosition[1], | ||
- | if not self: | ||
- | | ||
- | | ||
- | 2 ^ OBJECT_FLAG.WATER: | ||
- | then | ||
- | MyMod: | ||
- | .. tostring(_globalPosition)) | ||
- | return _globalPosition[2] | ||
- | else | ||
- | return raycastResult[" | ||
- | end | ||
- | end | ||
- | |||
- | You can do the same with the ground by replacing OBJECT_FLAG.WATER by OBJECT_FLAG.GROUND | ||
- | |||
- | If the water (or the ground) is not found (for instance when the _globalPosition out of the map) then a warning is edited in the logs, and the code return the Y of the _globalPosition. | ||
- | |||
- | |||
- | |||
preview.1587570651.txt.gz · Last modified: 2020/04/22 11:50 by vjraymon