Collisions whilst rotating

Blitz3D Forums/Blitz3D Programming/Collisions whilst rotating

Mousey(Posted 2003) [#1]
I am having a problem figuring out how to "walk" a cube across a plane, so that it properly moves on its edges without them sinking into the ground, yet doesn't float above the ground when it is level. I hope this makes sense! Here is some code that will hopefully illustrate my problem; any help would be very much appreciated!

Graphics3D 800,600
SetBuffer BackBuffer()
AmbientLight 255,255,255

camera=CreateCamera()
PositionEntity camera,0,1,0

plane = CreatePlane()
EntityColor plane,0,128,0
EntityType plane,2

cube = CreateCube()
EntityColor cube,0,0,128
PositionEntity cube,6,1,8
EntityType cube,1

Collisions 1,2,2,2

While Not KeyHit(1)

; move cube up and down to test collision with plane
If KeyDown(200) Then TranslateEntity cube,0,0.1,0
If KeyDown(208) Then TranslateEntity cube,0,-0.1,0

; move cube from right to left whilst turning it
TranslateEntity cube,-0.01,0,0
TurnEntity cube,0,0,0.3

; this line just for test collision, I don't want the cube to be aligned with the plane
If EntityCollided(cube,2) Then AlignToVector cube,CollisionNX(cube,1),CollisionNY(cube,1),CollisionNZ(cube,1),2

UpdateWorld()
RenderWorld()
Flip

Wend
End



Bot Builder(Posted 2003) [#2]
Hmmmm. I'm afraid that this is not possible with blitzes collisions(unless you do somthing clever like sphere collisions on each vertice). A rolling cube huh? Well, you could figure out the location of each vertice, and if no vertices are on groundlevel, then you could figure out which one is closest to the ground, and move the cube enough to get the vertice on the ground. I believe you'll have to also abandon blitz collisions, but if you still need the cube to detect collisions, you can parent a pivot to it, and set up collisions for the pivot. the collisions won't affect the cube, but you can detect them.

This should do the trick:
Graphics3D 800,600
SetBuffer BackBuffer()
AmbientLight 255,255,255

camera=CreateCamera()
PositionEntity camera,0,1,0

plane = CreatePlane()
EntityColor plane,0,128,0
;EntityType plane,2

cube = CreateCube()
EntityColor cube,0,0,128
PositionEntity cube,6,1,8
;EntityType cube,1

;Collisions 1,2,2,2

While Not KeyHit(1)

; move cube up and down to test collision with plane
If KeyDown(200) Then TranslateEntity cube,0,0.1,0
If KeyDown(208) Then TranslateEntity cube,0,-0.1,0

; move cube from right to left whilst turning it
TranslateEntity cube,-0.01,0,0
TurnEntity cube,0,0,0.3

min#=1000
cs=GetSurface(cube,1)
For a=0 To CountTriangles(cs)-1
 TFormPoint VertexX(cs,a),VertexY(cs,a),VertexZ(cs,a),cube,0
 If Abs(TFormedY())<min# Then 
  min#=Abs(TFormedY())
  resp#=TFormedY()
 EndIf 
Next
DebugLog min#
TranslateEntity cube,0,-resp#,0

cube,CollisionNX(cube,1),CollisionNY(cube,1),CollisionNZ(cube,1),2

UpdateWorld()
RenderWorld()
Flip

Wend
End



Mousey(Posted 2003) [#3]
Fantastic! Thanks so much for your help with this. :)

Just in case someone else wants to run bot builder's code, I should mention that this line:
cube,CollisionNX(cube,1),CollisionNY(cube,1),CollisionNZ(cube,1),2

should also be remmed out.


DrakeX(Posted 2003) [#4]
looks like that line should've been

AlignToVector cube,CollisionNX(cube,1),CollisionNY(cube,1),CollisionNZ(cube,1),2

maybe it was some leftover code from another method he was trying.