Blitz3D Collision Example Fix (better way?)

Blitz3D Forums/Blitz3D Programming/Blitz3D Collision Example Fix (better way?)

After getting recent Blitz3D Update, retried the Collisions Example in the manual, but the collisions didn't work as expected (see ***** box in code). Finally discovered a fix that seems to work. Anyone have a better way to do this? Is this really a bug or am I doing something wrong?

(This is my first actual post; if I'm doing something the wrong way or in the wrong place, please let me know.)

; Collisions Example - modified from Blitz3D Manual
; -------------------------------------------------

Graphics3D 640,480
SetBuffer BackBuffer()

; Set collision type values
type_ground=1
type_character=2
type_scenery=3

camera=CreateCamera()
RotateEntity camera,45,0,0
PositionEntity camera,0,15,-10
light=CreateLight()
RotateEntity light,45,0,0

; Create sphere 'character'
sphere=CreateSphere( 32 )
EntityColor sphere,0,0,255
EntityRadius sphere,1
EntityType sphere,type_character
PositionEntity sphere,0,7,-4;0,7,0

; Create cube 'scenery'
cube=CreateCube()
ScaleEntity cube,1,1,1;2,2,2
EntityColor cube,255,255,255;0,0,255
EntityRadius cube,2
EntityBox cube,-2,-2,-2,4,4,4
EntityType cube,type_scenery
PositionEntity cube,4,7,-4

; Create visual of EntityRadius
cubeRadiusCollisionZone=CreateSphere(32)
EntityColor cubeRadiusCollisionZone, 255,0,0
PositionEntity cubeRadiusCollisionZone, 4,7,-4 ; same as cube
ScaleEntity cubeRadiusCollisionZone, 2,2,2
EntityAlpha cubeRadiusCollisionZone, 0.5

; Create visual of EntityBox
cubeBoxCollisionZone=CreateCube()
EntityColor cubeBoxCollisionZone, 0,255,0
PositionEntity cubeBoxCollisionZone, 4,7,-4 ; same a cube
ScaleEntity cubeBoxCollisionZone, 2,2,2
EntityAlpha cubeBoxCollisionZone, 0.2

; Set collision method and response values
method=2
response=2
method_info$="ellipsoid-to-polygon"

While Not KeyDown( 1 )
	
	x#=0 :y#=0 : z#=0	
	If KeyDown( 203 )=True Then x#=-0.1
	If KeyDown( 205 )=True Then x#=0.1
	If KeyDown( 208 )=True Then z#=-0.1
	If KeyDown( 200 )=True Then z#=0.1	
	MoveEntity sphere,x#,y#,z#
	MoveEntity sphere,0,0,0; took out gravity when took out ground;-0.02,0 ; gravity
	
	; Change collision method
	If KeyHit( 50 )=True Then
		method=method+1
		If method=5 Then method=1
		If method=1 Then method_info$="ellipsoid-to-sphere"
		If method=2 Then method_info$="ellipsoid-to-polygon"
		If method=3 Then method_info$="ellipsoid-to-box"
		If method=4 Then method_info$="invalid type; no collision"
		
	EndIf
	
;************************************************************************
	; If ClearCollisions is commented out (line doesn't exist in the Manual example),
	; the collision is always defined by the "method=" line before the While..Wend loop begins
	; (Tested with Blitz3D w/Updates 1.85 - 1.98 (both Fullscreen and Windowed) IDE and .exe)
	; Of course, if you had declared other Collisions, they get cleared here also!
	; so you would need to enable them again if you still want them active (eg-Collision w/ground)
	; Me thinks there might be a better way??
	ClearCollisions
;************************************************************************
	
	; Enable collisions between type_character and type_scenery
	Collisions type_character, type_scenery, method, response
	
	; Perform collision checking
	UpdateWorld	
	RenderWorld	
	Text 0,0,"Use cursor keys to move sphere"
	Text 0,20,"Press M to change collision Method (currently: "+method_info$+")"
	Text 0,60,"Collisions type_character,type_scenery,"+method+","+response
	Flip
Wend
End


FYI, last night, before Update from 1.64 (I know, a little procrastination going on for several months...."If it ain't broke, don't fix it...."), the example worked for me. So, wondering what changed. BTW, the reason for the indepth Collision study was to see if possible to use Sprites in Collisions with 3D. Apparently, it works okay for ellipsoid-to-sphere and ellipsoid-to-box but not ellipsoid-to-polygon. Anyone know if it's safe to use Sprites in Collisions?

My revised example actually shows the semi-transparent EntityRadius/EntityBox areas, so in any case it's an okay way to really kind of visualize how these Collisions work. I think I kind of "get it" now?! Glitch-solving can be quite educational, but it sure does take a lot of time and lost sleep!!!

Does anybody know of a better way to get the example to work without the ClearCollisions command (and, of course, the resetting of all the desired Collisions)?

Thanks :-)

Well, clearing a collisions rule before redefining it seems to be the correct procedure now (came across it recently also). The example is most likely out of date (and if it's in the physical manual then thank goodness for print-on-demand!) but you might want to make a bug report and see if Mark intended this behaviour (because it does mean reiterating every single collision rule in order to alter a single one).

Sprites can be used in collisions - just be sure to use box or sphere for their collision type, don't use polygon. For that matter, pivots can be used in the same manner (it has it's uses...).

Thanks for the replies. Guess I'm on the right track. So, I'll make a note: "Always do ClearCollisions first if changing a Collsion definition."

but you might want to make a bug report and see if Mark intended this behaviour (because it does mean reiterating every single collision rule in order to alter a single one).
- Where is the best place to post it - Blitz3D Bug Reports or Blitz3D Manual ??

I hadn't really thought about using a pivot in a collision - interesting idea. I had a problem with my camera viewing OUTSIDE of the world cylinder. Maybe there's a way to create a pivot point collision check to avoid this. Or as the above link brought up, maybe using an invisible cube as "feet" for the camera may be an idea. I guess I'm understanding Collisions better now - maybe just need a bigger CollisionRadius on the camera. Any other ideas for keeping the camera inside walls??


Where is the best place to post it - Blitz3D Bug Reports or Blitz3D Manual ??


Start with the Manual - it's more likely to be an oversight in the code than a bug in Blitz, thinking about it.