why doesnt this collison work?

Blitz3D Forums/Blitz3D Beginners Area/why doesnt this collison work?

danjo(Posted 2005) [#1]
i was messing around, and i found i must be doing something wrong. i keep looking at it , but it looks ok to me.. i need fresh eyes please.
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
cam=CreateCamera()
PositionEntity cam,0,10,20

cube1=CreateCube()
EntityType cube1,1
EntityColor cube1,255,0,0

ball=CreateSphere()
bx#=10
EntityType ball,2
ScaleEntity ball,1.2,1.2,1.2
EntityColor ball,0,0,255

light=CreateLight(cam)
PositionEntity light,0,10,20
PointEntity cam,cube1
PointEntity light,cube1

Collisions 1,2,3,1

While Not KeyHit(1)
Cls

If KeyDown(205) Then bx#=bx#-0.1
If KeyDown(203) Then bx#=bx#+0.1
PositionEntity ball,bx#,0,0

UpdateWorld
RenderWorld
If EntityCollided(ball,cube1)Then Text 0,0,"collision"
Flip
Wend
End



TomToad(Posted 2005) [#2]
You're checking collision of the box with the sphere, but you're moving the sphere toward the box. Change Collisions 1,2,3,1 to Collisions 2,1,3,1. Also wouldn't be a bad idea to set the EntityRadius and EntityBox commands.


danjo(Posted 2005) [#3]
ah - it was driving me mad. and i just had to know why!

ok, a variation..
can anyone explain to me why the white ball, which should remain inside the blue ball (entityx()) position, doesnt?
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
cam=CreateCamera()
PositionEntity cam,0,10,20

cube1=CreateCube()
EntityType cube1,1
EntityColor cube1,255,0,0

ball=CreateSphere()
bx#=10
EntityType ball,2
ScaleEntity ball,1.2,1.2,1.2
EntityColor ball,0,0,255
EntityAlpha ball,0.6

ball2=CreateSphere()


light=CreateLight(cam)
PositionEntity light,0,10,20
PointEntity cam,cube1
PointEntity light,cube1

Collisions 2,1,3,1

While Not KeyHit(1)
Cls

If KeyDown(205) Then bx#=bx#-0.1
If KeyDown(203) Then bx#=bx#+0.1
PositionEntity ball,bx#,0,0
PositionEntity ball2,EntityX(ball),0,0
UpdateWorld
RenderWorld
If CountCollisions(ball)>0 Then Text 0,0,"collision"
Flip
Wend
End

this isnt meant for anything, im just doing some tests to help figure things out? - like why the smaller ball keeps moving when it shouldnt.


scribbla(Posted 2005) [#4]
at a qucik glance your destination type in collisions is set to test for the cube1 to detect a moving object i think you have to set up collisions for both


Collisions 1,2,3,1
Collisions 2,1,3,1


scribbla(Posted 2005) [#5]
too late again ;)


TomToad(Posted 2005) [#6]
Ok, I'll try to explain this :-) You move ball, then move ball2 to ball's position, then you call UpdateWorld which detects the collision and moves ball back to where the collision occured leaving ball2 at the old ball position. Solution is to move the PositionEntity ball2,EntityX(ball),0,0 after UpdateWorld.


danjo(Posted 2005) [#7]
ah- again. thanks. rather simple explanations :D