level collision. One surface, how to make it solid

Blitz3D Forums/Blitz3D Beginners Area/level collision. One surface, how to make it solid

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

If the level is all one mesh then just give it an 'EntityType' let's say 'EntityType level(or whatever you called it),2' - set up the player with 'EntityType player,1' - set collisions with 'Collisions 1,2,2,3'

The following is slightly different as I create the level on-the-fly - but you should be able to pick the bones of it:

; mini-mini Sausage Dweller - puki - 2004

Graphics3D 800,600; change this to whatever you want
HidePointer

walkspeed#=.1; speed at which the camera/player moves at - originally set to .1 (just in case you changed it)
no_of_data=11; number of lines of data in mapdata

SeedRnd MilliSecs(); this is vital for random numbers (helps the bot choose more randomly)

;create the ground
floor1=CreatePlane()
EntityColor floor1,50,255,50
PositionEntity floor1,0,-2.3,0 
EntityType floor1,2

;create camera/player
Global player=CreatePivot()
Global camera=CreateCamera(player)
CameraRange camera,1,100
CameraClsColor camera,50,50,200; colour the sky
PositionEntity player,5,1,-20
EntityType player,1

wallheight#=2.5
;create wall block
block=CreateCube()
ScaleEntity block,2.5,wallheight,2.5
EntityColor block,100,100,100
EntityAlpha block,.3
EntityType block,2
HideEntity block


.mapdata
Data "01000000000"
Data "03111311130"
Data "01000100010"
Data "01000100010"
Data "01000100010"
Data "03111313130"
Data "01000101010"
Data "01000313130"
Data "01000101010"
Data "03111313130"
Data "00000000000"

;draw the 2D maze data into a 3D world
Restore mapdata; find the block of data
number_of_blocks=0
wpc=0
For c=0 To no_of_data-1
Read m$
For a=1 To 11; loop through the data

	;draw the wall blocks
	If Mid$(m$,a,1)="0"
		newblock=CopyEntity(block); make a copy of the original entity
		PositionEntity newblock,xx,0.2,zz
		number_of_blocks=number_of_blocks+1; not necessary - just counts total number of blocks
	End If

;NOTE "1"'s are ignored, the are empty spaces - the values I have chosen are irrelevent

;this code block is used to space out the 'wall blocks'
x=x+1; a simple counter
xx=xx+5; increment the spacing
If x=11; maximum number of items (numbers 0-9) in data statment
	x=0; make it=0 as we are at the end of a line of data
	zz=zz+5; increment the spacing
	xx=0; move the location of the next 'wall block' back to position 0
EndIf

Next 
Next


Collisions 1,2,2,3; stops you walking though the walls


; MAIN LOOP ***************************************************
While Not KeyHit(1)

pz=EntityZ(player)
px=EntityX(player)

Gosub MoveCamera

UpdateWorld
RenderWorld
Flip
Wend
End
;---------------------------------------------------------------

; I could have used functions - but gosubs will suffice (no need to use 'Global' variables)
.MoveCamera
mx#=-.25*MouseXSpeed()
my#=.25*MouseYSpeed()
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

TurnEntity player,0,mx#,0,1
TurnEntity camera,my#,0,0,0

If KeyDown(200) Or KeyDown(17) Then MoveEntity player,0,0,walkspeed
If KeyDown(208) Or KeyDown(31) Then MoveEntity player,0,0,-walkspeed
If KeyDown(205) Or KeyDown(32) Then MoveEntity player,walkspeed,0,0
If KeyDown(203) Or KeyDown(30) Then MoveEntity player,-walkspeed,0,0
Return