The collisions method is the best by far (or at least the easiest). When using collisions you should follow these steps:
1. Apply collision numbers to each mesh (i.e. ground mesh=1, car mesh=2) by using EntityType mesh,num.
2. Apply a collision radius to each mesh. This isn't necessary for every mesh but as far as I can tell it doesn't hurt although to be exact this only needs to be applied to meshes that require sphere collision (EntityRadius mesh,x radius(,y radius)) or box collisions (EntityBox mesh,x,y,z,width,height,depth).
3. Then setup the collisions list using the collisions command.
4. Then in your main loop it's always good to apply a little gravity to the car so that it doesn't appear to hover when moving from high to low ground.
Probably not the most in depth description but the following code might be more explanatory:
; define collision types
Const groundcoltype=1
Const carcoltype=2
; load objects
ground=LoadMesh("ground.b3d")
car=LoadMesh("car.b3d")
; apply entity types to objects
EntityType ground,groundcoltype
EntityType car,carcoltype
; apply entity radius to objects
; nb: only needed on car as the
; ground is going to use poly collision method
; NBB: probably better using a box for a car but
; this is just an example ;)
EntityRadius car,MeshWidth(car),MeshHeight(car)
; clear collisions list
ClearCollisions
; add a collision to the list for car on ground
; should be sphere to poly (2)
; gonna use sliding but prevent auto slide down slope (3)
Collisions carcoltype,groundcoltype,2,3
;
; other stuff here
;
; main loop
While Not KeyHit(1)
;
; update game stuff here
;
; apply a little gravity to car
PositionEntity car,EntityX(car),EntityY(car)-1,EntityZ(car)
UpdateWorld()
RenderWorld()
Flip
Wend
The UpdateWorld() should handle all the collisions for you and because you've told Blitz to use collisions for the car against the ground mesh, even though you apply gravity the car will always move along the contours of the ground mesh.
Hope this helps.
|