[bb] Push a row of cubes! by Ross C [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : Push a row of cubes!
Author : Ross C
Posted : 1+ years ago

Description : Say you have your player, and a row of cubes. You push the first cube, and any cubes, that the first one bumps into, get pushed as well. WASD to move.

Code :
Code (blitzbasic) Select
Graphics3D 640,480,16
SetBuffer BackBuffer()

Const cube_col=1
Const sphere_col=2


Global light= CreateLight()


Global camera=CreateCamera()
PositionEntity camera,0,40,0
RotateEntity camera,90,0,0

Global sphere=CreateSphere()
EntityType sphere,sphere_col

Global level=CreatePivot()

Dim cube(10)
For loop=0 To 10
cube(loop)=CreateCube()
PositionEntity cube(loop),-10,0,-10+loop*2
EntityType cube(loop),cube_col
EntityParent cube(loop),level
Next



Collisions 1,2,2,2
Collisions 1,1,2,2
Collisions 1,3,2,2

While Not KeyHit(1)

If KeyDown(30) MoveEntity level,0.1,0,0
If KeyDown(32) MoveEntity level,-0.1,0,0
If KeyDown(17) MoveEntity level,0,0,-0.1
If KeyDown(31) MoveEntity level,0,0,0.1

UpdateWorld
updatecubes() ; make sure collisions doesn't push the cubes downwards or upwards
RenderWorld
Flip
Wend
End

Function updatecubes()
For loop=0 To 10
PositionEntity cube(loop),EntityX(cube(loop)),0,EntityZ(cube(loop))
Next
End Function


Comments :


simonh(Posted 1+ years ago)

 Hey that's quite cool. I never realised the Blitz collision system could do that.


simonh(Posted 1+ years ago)

 OK, I've had a second look and it turns out this is quite a clever camera trick. The Blitz collision system will only ever move source entities, so it can never really 'push' anything. What's happening here is that due to the camera view it looks as if the cubes are being pushed by the sphere, whereas in fact the cubes are being pushed into the sphere (and each other).Still, nice trick!


Ross C(Posted 1+ years ago)

 Yeah, it is useless if you have two players on screen, because your actually moving the level. I was still surprised that blitz collisions could do this tho :)