why dosent work?

Blitz3D Forums/Blitz3D Programming/why dosent work?

Santiworld(Posted 2008) [#1]
ball physics...

i want when the balls collisions...

the diference bettwen last position and actual, determinated de x y and z speed of the ball...

but dosent work

----



piso = CreatePlane()
EntityColor piso,30,100,40
EntityType piso,2
luz = CreateLight(1)
TurnEntity luz,45,45,45

cam = CreateCamera()
PositionEntity cam,20,10,50
CameraClsColor cam,40,100,160
CameraFogMode cam,True
CameraFogRange cam, 100,1000
CameraFogColor cam,20,40,20








Type ball
Field entidad
Field sombra
Field x#
Field y#
Field z#
Field vx#
Field vy#
Field vz#
Field dx#
Field dy#
Field dz#
Field lx#
Field ly#
Field lz#
End Type

x=2

For i = 0 To 33
ball.ball = New ball
ball\entidad = CreateSphere(8)
PositionEntity ball\entidad,Rnd(-x,x),Rnd(10,50),Rnd(-x,x)
EntityColor ball\entidad,244,200,50
EntityType ball\entidad,1
EntityRadius ball\entidad,1

ball\sombra = CreateSphere(4)
EntityAlpha ball\sombra ,.5
ScaleEntity ball\sombra,1,.1,1
EntityColor ball\sombra,0,0,0
;ball\vz# = -.2
Next

box = CreateCube()
MoveEntity box,0,15,0
PointEntity cam,box
HideEntity box

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

g# = .01
f# = .999


While Not KeyHit(1)


For ball = Each ball







ball\vx# = ball\vx#*f
ball\vy# = ball\vy#*f
ball\vz# = ball\vz#*f



ball\vx# = ball\vx# + ball\dx#
ball\vy# = ball\vy# + ball\dy#
ball\vz# = ball\vz# + ball\dz#

TranslateEntity ball\entidad,ball\vx,ball\vz,ball\vy

PositionEntity ball\sombra,EntityX(ball\entidad,1),.1,EntityZ(ball\entidad,1)

If EntityCollided (ball\entidad,2) Then
ball\vz# = -ball\vz# * .9
ResetEntity ball\entidad
Else
ball\vz# = ball\vz# - g#
End If

ball\lx# = EntityX#(ball\entidad,1)
ball\ly# = EntityY#(ball\entidad,1)
ball\lz# = EntityZ#(ball\entidad,1)

ball\dx# = EntityX#(ball\entidad,1) - ball\lx#
ball\dy# = EntityY#(ball\entidad,1) - ball\ly#
ball\dz# = EntityZ#(ball\entidad,1) - ball\lz#

vx# = ball\vx#
vy# = ball\vy#
vz# = ball\vz#
Next


UpdateWorld
RenderWorld

Text 0,00,vx#
Text 0,20,vy#
Text 0,40,vz#

Flip
Wend
End
Return


puki(Posted 2008) [#2]
What is supposed to happen? Are they supposed to richochet off each other or something?


Santiworld(Posted 2008) [#3]
i want the balls have horizontal x y speed... when collided with other balls...


puki(Posted 2008) [#4]
Correct me if I am wrong, but when they collide you want them to move horizonatally away from their collision point. Like dropping marbles on a surface/ground and they all scatter horizontally?


puki(Posted 2008) [#5]
CollisionNX(), CollisionNY() and CollisionNZ() return the x,y and z components of the normal of a particular collision.

If CollisionNY() is smaller than the other two then it's horizontal.

Not tried it, but it seems to make sense.