User Tools

Site Tools


preview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
preview [2020/04/22 11:49] vjraymonpreview [2020/04/22 11:50] vjraymon
Line 5: Line 5:
  
     function MY_CUSTOM_COMPONENT:computeWaterElevation(_globalPosition)     function MY_CUSTOM_COMPONENT:computeWaterElevation(_globalPosition)
-    local raycastResult = {}+        local raycastResult = {}
            
-    -- Raycast from the _globalPosition + 1000 +        -- Raycast from the _globalPosition + 1000 
-    -- to _globalPosition - 1000 +        -- to _globalPosition - 1000 
-    -- only on objects with a WATER flag +        -- only on objects with a WATER flag 
-    local FromPosition = { _globalPosition[1], _globalPosition[2]+1000, _globalPosition[3] } +        local FromPosition = { _globalPosition[1], _globalPosition[2]+1000, _globalPosition[3] } 
-    local ToPosition = { _globalPosition[1], _globalPosition[2]-1000, _globalPosition[3] } +        local ToPosition = { _globalPosition[1], _globalPosition[2]-1000, _globalPosition[3] } 
-    if not self:getLevel():rayCast(FromPosition, +        if not self:getLevel():rayCast(FromPosition, 
-                                   ToPosition, +                                       ToPosition, 
-                                   raycastResult, +                                       raycastResult, 
-                                   2 ^ OBJECT_FLAG.WATER:toNumber()) then +                                       2 ^ OBJECT_FLAG.WATER:toNumber()) 
-         MyMod:logWarning("MY_CUSTOM_COMPONENT: Water not found on the vertical of "+        then 
 +            MyMod:logWarning("MY_CUSTOM_COMPONENT: Water not found on the vertical of "
                           .. tostring(_globalPosition))                           .. tostring(_globalPosition))
-         return _globalPosition[2] +            return _globalPosition[2] 
-    else +        else 
-         return raycastResult["Position"][2]+            return raycastResult["Position"][2] 
 +        end
     end     end
- end 
  
 You can do the same with the ground by replacing OBJECT_FLAG.WATER by OBJECT_FLAG.GROUND You can do the same with the ground by replacing OBJECT_FLAG.WATER by OBJECT_FLAG.GROUND

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki