TerrainY equivalent for meshes??

Blitz3D Forums/Blitz3D Programming/TerrainY equivalent for meshes??

PsychicParrot(Posted 2003) [#1]
I have a mesh acting as a terrain and I want to get the equivalent of the terrainy() so that I can place a car on it. I tried to build it with collisions, but got absolutely no-where other than confused. I tried using aligntovector, based on a collision of a 'terrain detect' pivot under the car - which, again, failed miserably! What I thought of was - if there was a way of finding the nearest vertex on the mesh perhaps there would be a way of calculating the y? Man, I don't know. I've been working on this for two days now and it's making me wierd. Any help would be appreciated and any code would be even more appreciated ;)


Sunteam Software(Posted 2003) [#2]
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.


jhocking(Posted 2003) [#3]
I do a LinePick straight down every frame to detect the ground beneath the player.


TartanTangerine (was Indiepath)(Posted 2003) [#4]
Have you looked at the demo code called "Driver" in the "mak" directory of Blitz3d Samples (As supplied on the b3d cd)