advanced collision detection

Blitz3D Forums/Blitz3D Programming/advanced collision detection

is it possable for when a ball hits a wall for sparks to appear on the exact place the ball hit the wall?

sure

Ball position x,y,z + radius + yaw + roll + pitch + 90°

Or CollisionX(), CollisionY() and CollisionZ()?

Here is a little example I put together using CollisionX(), CollisionY(), and CollisionZ()
turn the camera with the cursor keys and fire a ball at the wall with the space key.
Graphics3D 800,600,32,2
SetBuffer BackBuffer()

Type TSpark
	Field x#
	Field y#
	Field z#
	Field Time
	Field Entity
End Type


Global ball = CreateSphere() ;the big ball
room = CreateCube() ;the room you will be in
ScaleEntity room,-10,-10,-10 ;increase the room and invert the scale so we can see it from inside
;set up collisions between the room and the ball
EntityType ball,1
EntityType room,2
EntityRadius ball,1,1
Collisions 1,2,2,1

camera = CreateCamera() ;camera
RotateEntity camera,-45,45,0 ;point the camera to a corner of the room
light = CreateLight() ;a light
RotateEntity light,45,45,0
move = False ;flag set when ball is fired

EntityColor room,0,0,255
EntityColor ball,0,255,0

While Not KeyHit(1)
	If KeyDown(208) Then TurnEntity camera,.5,0,0 ;move camera with cursor keys
	If KeyDown(200) Then TurnEntity camera,-.5,0,0
	If KeyDown(203) Then TurnEntity camera,0,.5,0
	If KeyDown(205) Then TurnEntity camera,0,-.5,0
	If KeyHit(57) ;Space key to fire the ball
		RotateEntity ball, EntityPitch(camera),EntityYaw(camera),EntityRoll(camera) ;point the ball to where the camera is facing
		move = True ;set flag
	End If
	
	If move
		MoveEntity ball,0,0,.1 ;move ball forward
	End If
	TurnEntity light,.1,.2,.3 ;rotate the light
	UpdateWorld 
	If CountCollisions(Ball) ;if ball is involved in collision with room
		CreateSparks() ;create a bunch of sparks
		PositionEntity Ball,0,0,0 ;put the ball back at camera
		move = False ;reset flag
	End If
	UpdateSparks() ;move sparks
	RenderWorld
	Flip
Wend

Function CreateSparks()
	For Coll = 1 To CountCollisions(Ball) ;ball might've collided with more than one wall
		For i = 1 To 100 ;100 sparks
			Spark.TSpark = New TSpark
			Spark\x = CollisionX(Ball,Coll) ;x,y,z of collision between ball and room
			Spark\y = CollisionY(Ball,Coll)
			Spark\z = CollisionZ(Ball,Coll)
			Spark\Entity = CreateSphere() ;create a sphere spark
			EntityColor Spark\Entity,255,255,0 ;color it yellow
			PositionEntity Spark\Entity,Spark\x,Spark\y,Spark\z ;position it at the collision point
			ScaleEntity Spark\Entity,.1,.1,.1 ;scale to really small
			RotateEntity Spark\Entity,Rand(0,359),Rand(0,359),Rand(0,359) ;rotate it to a random direction
			Spark\Time = MilliSecs() + 3000 ;Sparks will disappear after a few seconds
		Next
	Next
End Function

Function UpdateSparks()
	For Spark.TSpark = Each TSpark
		If MilliSecs() < Spark\Time ;if there is still time
			MoveEntity Spark\Entity,0,0,.3 ;move the spark forward a bit
		Else
			FreeEntity Spark\Entity ;otherwise remove the spark
			Delete Spark
		End If
	Next
End Function


nono, i meant in 2D