December 03, 2020, 07:47:00 PM

Author Topic: [bb] Push a row of cubes! by Ross C [ 1+ years ago ]  (Read 638 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Push a row of cubes! by Ross C [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
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
  1. Graphics3D 640,480,16
  2. SetBuffer BackBuffer()
  3.  
  4. Const cube_col=1
  5. Const sphere_col=2
  6.  
  7.  
  8. Global light= CreateLight()
  9.  
  10.  
  11. Global camera=CreateCamera()
  12. PositionEntity camera,0,40,0
  13. RotateEntity camera,90,0,0
  14.  
  15. Global sphere=CreateSphere()
  16. EntityType sphere,sphere_col
  17.  
  18. Global level=CreatePivot()
  19.  
  20. Dim cube(10)
  21. For loop=0 To 10
  22.         cube(loop)=CreateCube()
  23.         PositionEntity cube(loop),-10,0,-10+loop*2
  24.         EntityType cube(loop),cube_col
  25.         EntityParent cube(loop),level
  26. Next
  27.  
  28.  
  29.  
  30. Collisions 1,2,2,2
  31. Collisions 1,1,2,2
  32. Collisions 1,3,2,2
  33.  
  34. While Not KeyHit(1)
  35.        
  36.         If KeyDown(30) MoveEntity level,0.1,0,0
  37.         If KeyDown(32) MoveEntity level,-0.1,0,0
  38.         If KeyDown(17) MoveEntity level,0,0,-0.1
  39.         If KeyDown(31) MoveEntity level,0,0,0.1
  40.  
  41.         UpdateWorld
  42.         updatecubes() ; make sure collisions doesn't push the cubes downwards or upwards
  43.         RenderWorld
  44.         Flip
  45. Wend
  46. End
  47.  
  48. Function updatecubes()
  49.         For loop=0 To 10
  50.                 PositionEntity cube(loop),EntityX(cube(loop)),0,EntityZ(cube(loop))
  51.         Next
  52. 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 :)


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal