Moving Platforms

Blitz3D Forums/Blitz3D Programming/Moving Platforms

Naughty alien, that code was very helpful!
(edit)
In the meanwhile I tried a theory that worked so-so.
The idea was to move everything except the cube/platform.
So that collision reponses were inverted:
;-----------------------------------------------------------------------------------------------------
;													setup 3d world
;-----------------------------------------------------------------------------------------------------

	;setup graphics
	Graphics3D 800, 600, 0, 2
	SetBuffer BackBuffer()

	
	;global pivot
	pivot = CreatePivot()
	
	;create camera (type 1)
	camera = CreateCamera(pivot)
	MoveEntity camera, 0, 5, -35
	
	;create floor (type 3)
	plane = CreatePlane(1, pivot)
	MoveEntity plane, 0, -1, 0
	EntityTexture plane, MakeTexture()
	
	;create player (sphere)
	sphere = CreateSphere(6, pivot)
	EntityColor sphere, 255, 0, 0
	EntityRadius sphere, 1
	
	;create object ()
	cube = CreateCube(pivot)
	ScaleEntity cube, 2, 1, 2
	EntityColor cube, 0, 255, 0
	PositionEntity cube, 5, 0.5, 0


;-----------------------------------------------------------------------------------------------------
;													setup collisions
;-----------------------------------------------------------------------------------------------------
	
	EntityType sphere, 	1
	EntityType plane, 	2
	EntityType cube, 	2
	
	Collisions 1, 2, 2, 1
		
;-----------------------------------------------------------------------------------------------------
;														main loop
;-----------------------------------------------------------------------------------------------------

	;time
	t# = 0
	
	Repeat
	
		;move everything except the cube
		t# = t# + 1
		zz# = Sin(t) / 5.0
		EntityParent cube, 0
		MoveEntity pivot, 0, 0, zz#
		EntityParent cube, pivot
	
		;move sphere
		If KeyDown(203) Then iMoveEntity sphere, -0.5, 0, 0
		If KeyDown(205) Then iMoveEntity sphere, +0.5, 0, 0
		If KeyDown(200) Then iMoveEntity sphere, 0, 0, +0.5
		If KeyDown(208) Then iMoveEntity sphere, 0, 0, -0.5
		If KeyDown(30) Then iMoveEntity sphere, 0, -0.5, 0
		If KeyDown(44) Then iMoveEntity sphere, 0, +0.5, 0
		
		;gravity
		If Not(EntityCollided(sphere, 2)) Then
			UpdateWorld 0
			TranslateEntity sphere, 0, -0.25, 0
		End If
		
		UpdateWorld()			
		RenderWorld()
		
		Color 255, 255, 255	
		Text 0, 0, "X:" + EntityX(sphere, 1) 
		Text 0, 20, "Y:" + EntityY(sphere, 1) 
		Text 0, 40, "Z:" + EntityZ(sphere, 1)
		Flip
		
	Until KeyHit(1)
	
	End

;-----------------------------------------------------------------------------------------------------
;												   iMoveEntity()
;-----------------------------------------------------------------------------------------------------
;update first, then move
Function iMoveEntity(ent, x#, y#, z#)

	UpdateWorld 0
	MoveEntity ent, x, y, z
	
End Function

;-----------------------------------------------------------------------------------------------------
;												   MakeTexture()
;-----------------------------------------------------------------------------------------------------
;create texture
Function MakeTexture()

	tex = CreateTexture(32, 32, 9)
	Color 0, 0, 0
	Rect 0, 0, 32, 32
	Color 0, 0, 255
	Rect 0, 0, 16, 16
	CopyRect 0, 0, 32, 32, 0, 0, BackBuffer(), TextureBuffer(tex)
	
	Return tex
	
End Function