Why no collision here (short code, no media)

Blitz3D Forums/Blitz3D Beginners Area/Why no collision here (short code, no media)

Tobo(Posted 2009) [#1]
Dear all.

I have a sphere travelling towards an elongated cube. I have told the collisions that when the sphere hits the box, stop; but it doesn't.

Graphics3D 800,600,32,2
SetBuffer BackBuffer()

bx#=-8

cam=CreateCamera()
PositionEntity cam,-2,4,-5
RotateEntity cam,30,0,0

light=CreateLight()

rod=CreateCube()
ScaleEntity rod,.5,3,.5
PositionEntity rod,2,0,0
EntityType rod,type_rod

ball=CreateSphere()
PositionEntity ball,-8,0,0
EntityType ball,type_ball

While Not KeyDown(1)

	bx#=bx#+0.03
	PositionEntity ball,bx#,0,0

	Collisions type_ball,type_rod,3,1

	UpdateWorld
	RenderWorld	
	
	Text 0,0,"BX = "+bx#
	
	Flip
	
Wend
End


I know I'm probably doing something ridiculously stupid, but I can't see what.

Any help much appreciated.

T


Hotshot2005(Posted 2009) [#2]
This should work :)

bx#=-8
type_rod=1
type_ball=2

Collisions type_ball,type_rod,2,1

Graphics3D 800,600,32,2
SetBuffer BackBuffer()

cam=CreateCamera()
PositionEntity cam,-2,4,-5
RotateEntity cam,30,0,0

light=CreateLight()

rod=CreateCube()
ScaleEntity rod,.5,3,.5
PositionEntity rod,2,0,0
EntityType rod,type_rod

ball=CreateSphere()
PositionEntity ball,-8,0,0
EntityType ball,type_ball

While Not KeyDown(1)

	bx#=bx#+0.03
	PositionEntity ball,bx#,0,0

	UpdateWorld
	RenderWorld	
	
	Text 0,0,"BX = "+bx#
	
	Flip
	
Wend
End



KronosUK(Posted 2009) [#3]
You haven't defined type_ball or type_rod
try

type_ball = 1
type_rod = 2

and move collisions type-ball,type_rod,3,1 out of the main loop.


Tobo(Posted 2009) [#4]
Thank you, guys (especially Kronos for explaining).

I too thought the collisions command came outside of the main loop, but pressing F1 twice on it gave an example where it was definately inside the loop!

Many thanks though, chaps.

T


Tobo(Posted 2009) [#5]
...another question:

I have amended the code to allow the sphere to slide along the elongated cube, and have rotated the cube slightly along its Z axis.

However, the sphere seems to jump through the cube about half way up!

Graphics3D 800,600,32,2
SetBuffer BackBuffer()

bx#=-8

type_ball = 1
type_rod = 2

cam=CreateCamera()
PositionEntity cam,-2,4,-5
RotateEntity cam,30,0,0

light=CreateLight()

rod=CreateCube()
ScaleEntity rod,.5,3,.5
PositionEntity rod,2,0,0
RotateEntity rod,0,0,-30
EntityType rod,type_rod

ball=CreateSphere()
PositionEntity ball,-8,0,0
EntityType ball,type_ball
EntityRadius ball,.7

Collisions type_ball,type_rod,3,2

While Not KeyDown(1)

	bx#=bx#+0.03
	PositionEntity ball,bx#,0,0

	

	UpdateWorld
	RenderWorld	
	
	Text 0,0,"BX = "+bx#
	
	Flip
	
Wend
End


I have tried both Collisions type_ball,type_rod,3,2 and Collisions type_ball,type_rod,3,3, but neither seems to work.

Any pointers?


GIB3D(Posted 2009) [#6]
Woo, methinks it has to do with the sliding and the position. If you position it far enough, it will have enough sliding power to go over the object :D Hope that helps


Tobo(Posted 2009) [#7]
If I position what how far; and why?


GIB3D(Posted 2009) [#8]
The red ball shows where the white ball would be if it didn't have collisions...

Also you need
Collisions type_ball,type_rod,2,2

not
Collisions type_ball,type_rod,3,2

the 3 would be for a box collision that you have to set yourself, it's not automaticly sized to the cube.

...ALSO... You said that Collisions type_character,type_scenery,method,response
is inside loop in the Collisions help. That is so you can change the way the collisions happen. If you don't want them to change, then you don't need it in the loop. Notice the "Collisions type_character,type_ground,2,2" close to the top of the help.