Aligning objects to a terrain

Blitz3D Forums/Blitz3D Programming/Aligning objects to a terrain

Skel(Posted 2003) [#1]
I was hoping someone might be able to give me a few clues as to how to get an object to align to the angles of a terrain. What I'm basically talking about is a little robot on wheels that drives around a terrain under player control. If the robot is going uphill, it should tilt back so that all wheels are planted on the terrain surface. Instead, the model remains flat and therefore the leading wheel is all that's touching the terrain...

I've had a look at the "driver" sample that comes with Blitz, but I just can't figure out how it's doing it...

If anyone wants to take a look at the big picture, the code can be found here:

http://www.evacademy.com/download/blitz/terrain_source.zip (1094Kb - sorry, it’s got all the textures and stuff in there too)

Any hints welcome - not looking for code or anything. Just a nice starting point...


Ross C(Posted 2003) [#2]
eh...sorry, i've lost my code for this thing but it alot to do with collisionnx then using aligntovector. wish i had the code..i'll have another look for it


Ross C(Posted 2003) [#3]
yipee! Managed to whip this together, hope it helps.

Graphics3D 800,600
SetBuffer BackBuffer()

light=CreateLight()
ground=CreatePlane()

camera=CreateCamera()

box=CreateCube()
PositionEntity box,0,2,0
PositionEntity camera,0,6,-20
RotateEntity ground,0,0,30
EntityType ground,2
EntityType box,1
Collisions 1,2,2,2


While Not KeyHit(1)

If KeyDown(200) Then MoveEntity box,0,0.1,0
If KeyDown(208) Then MoveEntity box,0,-0.1,0
If KeyDown(203) Then MoveEntity box,0.1,0,0
If KeyDown(205) Then MoveEntity box,-0.1,0,0

If EntityCollided(box,2) Then
	AlignToVector box,CollisionNX(box,1),CollisionNY(box,1),CollisionNZ(box,1),2
End If



UpdateWorld()
RenderWorld()

Flip
Wend
End

bye


Fader(Posted 2003) [#4]
I have some code for this. I will post it tomorrow (Monday).

Fader


Skel(Posted 2003) [#5]
Joker, that looks pretty good! Three lines of code and I'm much further along than I was. Just need to smooth it out now - it just jerks from one angle to another. I'll work on it...

Fader: I'd still love your input if it's not gonna put you out at all...

Thanks heaps for the help guys :)


Skel(Posted 2003) [#6]
...or, maybe just change the AlignToVector "rate" argument to a smooth transition! Isn't Blitz lovely? :)