Problem with Collisions in minib3d

Monkey Forums/Monkey Programming/Problem with Collisions in minib3d

donicamm(Posted 2013) [#1]
Does anyone see what is causing my collisions not to work? I'm trying to get my camera to collide with the cubes.

At first, I thought the issue might be happening, because the cubes were defined locally inside a loop, but then I tried just making one non-local cube and I still couldn't collide.

As far as I know, I am calling everything properly, but I am not super experienced with either minib3d or Monkey. Any help is appreciated, thanks.

Strict
Import mojo
Import minib3d

Global player:Int = 1
Global wall:Int = 2

Class Game Extends App
	
	Field Camera:TCamera
	Field Light:TLight, Light2:TLight
	Field Floor:TEntity
	Field Started:Bool
	Field wallMesh:TEntity
	
	Method OnCreate%()
		SetUpdateRate 30
		Return 0
	End


	Method OnUpdate%()
		If Not Started Then Return 0

		If KeyDown(KEY_UP)	
			Camera.MoveEntity 0,0,1
		Elseif KeyDown(KEY_DOWN)
			Camera.MoveEntity 0,0,-1
		Endif
		If KeyDown(KEY_LEFT)
			Camera.TurnEntity 0,2.5,0
		Elseif KeyDown(KEY_RIGHT)
			Camera.TurnEntity 0,-2.5,0
		Endif
		
		Collisions(player, wall, 1, 2)
		UpdateWorld()
		Return 0
	End

	
	Method Init:Void()		
		If Started Then Return
		Started = True		
		SetRender()		
		Camera = CreateCamera()
		Camera.CameraClsColor(180,210,220)
		Camera.MoveEntity 0,1.5,-10
	
		Floor=CreateGrid(15,15)
		Floor.ScaleEntity 10,1,10 
		Floor.PositionEntity -2,0,8
		Floor.EntityColor 55,95,0
		
		EntityType(Camera,player)
		EntityRadius (Camera, 1.5)
		
		
		For Local i%=0 To 11
			Local C:TEntity=CreateCube()
			C.MoveEntity Rnd(-50,50), 0,Rnd(-50,50)
			C.EntityColor Rnd(255),Rnd(255),Rnd(255)
			C.ScaleEntity Rnd(1,3), Rnd(6,12), Rnd(2,6)
			EntityType(C, wall)

		Next

		Light=CreateLight(1)
		Light.TurnEntity 35,-40,0
		Light.LightColor 222,222,111
		Light.AmbientLight 111,99,111
	End


	Method OnRender%()
		Init()
		RenderWorld()
		Return 0
	End
End




Function Main%()
	New Game
	Return 0
End



AdamRedwoods(Posted 2013) [#2]
you need to define the EntityCollision primitive for the "C" boxes as well.
		For Local i%=0 To 11
			Local C:TEntity=CreateCube()
			C.MoveEntity Rnd(-50,50), 0,Rnd(-50,50)
			C.EntityColor Rnd(255),Rnd(255),Rnd(255)
			C.ScaleEntity Rnd(1,3), Rnd(6,12), Rnd(2,6)
			C.EntityBox()  ''EntityBox() will auto-setup if there are no arguments
			EntityType(C, wall)

		Next


but you are also using spheres, which give strange results for boxes, try using:
Collisions(player, wall, COLLISION_METHOD_BOX, COLLISION_RESPONSE_SLIDE)

Collisions always tests the SOURCE as a sphere.

I've also just now noticed that two collision spheres overlapping don't give correct collision results. need to check that...


donicamm(Posted 2013) [#3]
Thanks you!

Just to make sure I'm understanding this properly, the reason my collisions were broken, is because I did not define anything for the boxes, which my camera could collide with, and calling EntityBox creates that collision box, for my boxes?


AdamRedwoods(Posted 2013) [#4]
Correct. You could have done C.EntityRadius(number) as well and used COLLISION_METHOD_SPHERE.