SyntaxBomb - Indie Coders

Languages & Coding => Blitz Code Archives => 3D Graphics - Effects => Topic started by: BlitzBot on June 29, 2017, 12:28:38 AM

Title: [bb] Crater Code by H. T. U. [ 1+ years ago ]
Post by: BlitzBot on June 29, 2017, 12:28:38 AM
Title : Crater Code
Author : H. T. U.
Posted : 1+ years ago

Description : A handy function that easily makes a nice round crater.  Assumes terrain sections are 1x1 Blitz units (add Step to change).  Also fun to tinker with, and easy to add particles, crater ring, etc.

entity=entity crater is created around
terrain=terrain in which the crater is formed
radius=crater's radius (default is 1)
th=maximum height of any terrain section (default is 100)
hardness=hardness of the ground, 1 is completely soft, 0 is completely solid (default is 1)


Code :
Code: BlitzBasic
  1. Function crater(entity,terrain,radius#=1,th#=100,hardness#=1)
  2.                         ex#=EntityX(entity)
  3.                         ez#=EntityZ(entity)
  4.  
  5.                         For x=-radius To radius
  6.                         For z=-radius To radius
  7.                                 If Sqr(x*x+z*z)<=radius And hardness<>0
  8.                                         d#=Sqr(x*x+z*z)
  9.                                        
  10.                                         h#=TerrainHeight(terrain,ex+x,ez+z)
  11.                                                                                
  12.                                         scale#=th/hardness
  13.                                        
  14.                                         h=h+d/scale-radius/scale
  15.                                         If h<0 Then h=0
  16.                                         ModifyTerrain terrain,ex+x,ez+z,h,True
  17.                                 EndIf
  18.                         Next
  19.                         Next
  20. End Function


Comments :


Guy Fawkes(Posted 1+ years ago)

 Nice man! =) Been lookin for 1 of these forever! =D Thanks man! =)~DarkShadowWing~

SimplePortal 2.3.6 © 2008-2014, SimplePortal