Code archives/3D Graphics - Maths/Push a row of cubes!
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
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. | |||||
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
| ||
Hey that's quite cool. I never realised the Blitz collision system could do that. |
| ||
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! |
| ||
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 :) |
Code Archives Forum