Collisions In Functions

Blitz3D Forums/Blitz3D Programming/Collisions In Functions

Ash_UK(Posted 2003) [#1]
Can anyone please tell if you are able to allow collisions within a function, i don't know how.
I have the game levels as seperate functions in order to make the code more readable and easier to navigate through, but my collision routines just don't seem to be working. :-(

Thanks for any help


IcE


Ash_UK(Posted 2003) [#2]
Anyone?

IcE


poopla(Posted 2003) [#3]
Collisions routines? Collisions in functions? Once collisions are set up blitz handles everything internaly. What are yopu trying to do/what are you doing now? A code example would be very helpful, thanks.


Ash_UK(Posted 2003) [#4]
Heres the code. It's not quite in functions at the moment but for some reason, the collision routines not working even though it isn't in a function. Can you tell me where i'm going wrong please?

The code:

;-------------------
;Graphics setup
;-------------------
SetBuffer BackBuffer()
Graphics3D 800,600
;---------
;Variables
;---------
Global player_speed#=10
Global stage=0
Global thickness=0.9
location$="blues room"
Global cam=CreateCamera()
CameraRange cam,1,10000
;---------
;Collision
;---------
pl=1
ro=2
;-----------------
;Initialise player
;-----------------
player_texture=LoadTexture("gfx/textures/blue_tex.bmp")
lightmap=LoadTexture("gfx/textures/lightmap.bmp",64)
Global player=LoadAnimMesh("gfx/models/blue.3ds")
Global player_cell=LoadAnimMesh("gfx/models/blue.3ds",player)
head=FindChild(player,"head")
EntityTexture head,player_texture
body=FindChild(player,"body")
EntityTexture body,player_texture
left_arm=FindChild(player,"larm")
EntityTexture left_arm,player_texture
right_arm=FindChild(player,"rarm")
EntityTexture right_arm,player_texture
left_foot=FindChild(player,"lfoot")
EntityTexture left_foot,player_texture
right_foot=FindChild(player,"rfoot")
EntityTexture right_foot,player_texture
cellshade(player_cell)
EntityTexture player,lightmap
EntityType player,pl,True
ScaleEntity player,.3,.3,.3
EntityRadius player,23


;blues_room()
;---------
;Variables
;---------
exists=1
;--------------
;Loading screen
;--------------
load_screen=LoadImage("gfx/loading.bmp")
DrawImage load_screen,0,0
Flip
;------------------
;Initialise objects
;------------------
blue_room=LoadAnimMesh("gfx/models/blue_room.3ds")
blue_room_cell=LoadAnimMesh("gfx/models/blue_room.3ds",blue_room)
cellshade(blue_room_cell)
EntityType blue_room,ro,True
cam_position=FindChild(blue_room,"campos")
point=FindChild(blue_room,"bluestart")

AmbientLight 255,255,255
;----------------
;Position objects
;----------------
PositionEntity blue_room,0,0,0
EntityParent cam,cam_position,False
;----------
;Collisions
;----------
Collisions pl,ro,2,3
;----
;Loop
;----
While exists=1

PointEntity cam,player
player_control()
If KeyDown(1) Then exists=0
RenderWorld

Flip

Wend

FreeImage load_screen
FreeEntity blue_room
End




Thanks for your kind help :-)


IcE


Ash_UK(Posted 2003) [#5]
Any help would be really appriciated. Please if anyone can tell me where i'm going wrong, i can't really progress any further until I have got it sorted out.


Thankyou
:-)


IcE


WolRon(Posted 2003) [#6]
Uh-hum!, you see, you checked for collisions before your loop even began. The correct method is to check for collisions each loop. Soooo...

Change this:

;---------- 
;Collisions 
;---------- 
Collisions pl,ro,2,3 
;---- 
;Loop 
;---- 
While exists=1 

PointEntity cam,player 
player_control() 
If KeyDown(1) Then exists=0 
RenderWorld 

Flip 

Wend 

FreeImage load_screen 
FreeEntity blue_room 
End 


to something along this line:

;---- 
;Loop 
;---- 
While exists=1 

PointEntity cam,player 
player_control() 
If KeyDown(1) Then exists=0 
;---------- 
;Collisions 
;---------- 
Collisions pl,ro,2,3 

UpdateWorld
RenderWorld
Flip 

;CountCollisions
;ClearCollisions

Wend 

FreeImage load_screen 
FreeEntity blue_room 
End 



(I believe you have to call collisions before updateworld (I'm at work right now and my memory stinks) and then countcollisions or clearcollisions if necessary)


Ash_UK(Posted 2003) [#7]
Thanks WolRon, i'll give it a try and see how it goes.
I really appriciate your help.

:-)


Ash_UK(Posted 2003) [#8]
Hmmm, no joy :-(. Ah well, thanks for the help all the same :-)
If there are any more solutions to this please keep me updated.
Many thanks

:-)


Ash_UK(Posted 2003) [#9]
Wait!!! i got it. Thankyou ever so much!!!!
It was only the "Updateworld" command i was missing ;-).
Thankyou for reminding about it,lol.

Thanks again

:-)