Distance

Blitz3D Forums/Blitz3D Programming/Distance

I tried something different and it says memory access violation, but when I remove CheckBox() from the loop it works just fine. If you have maplet just use the test.b3d because this is basicly test with some more stuff.
P.S. And also if you can make so it will display the right player for the won thing please do so. Or if you can get it to accept more players please do so.
AppTitle "Internet Game"

SetBuffer BackBuffer()

Game = StartNetGame()

If Game = 0 Then
	RuntimeError "Game Not Started"
EndIf

Graphics3D 1024,768,32,1

Name$ = Input$("What do you want your name to be? ")

Cls

NetPlayer = CreateNetPlayer(Name$)

If NetPlayer > 0 Then
	Print "Welcome, " + Name$
Else
	RuntimeError "Sorry. There was an error creating your player"
EndIf

Cls

Building = LoadMesh("Building.b3d")

If Building = 0 Then
	RuntimeError "File: 'Building.b3d' Not Found"
EndIf

Collisions 1,2,2,2

Global player = CreatePivot()
PositionEntity player,0,1,-1
EntityRadius player,.6
EntityType player,1

Global box = CreateCube()
ResizeMesh(box,1,1,1)
PositionEntity box,5,0,10

Global camera = CreateCamera(player)
CameraRange camera,.1,200

Global light = CreateLight()
LightColor light,32,32,32
TurnEntity light,45,-45,0

EntityFX Building,1
EntityType Building,2

sp#=.05
ey#=EntityY(player)

While Not KeyHit(1)
	
	yv#=EntityY(player)-ey
	ey=EntityY(player)
	
	If KeyHit(57) yv=.1

	MoveEntity player,0,yv-.005,0
	
	If KeyDown(30) TurnEntity camera,-2,0,0
	If KeyDown(44) TurnEntity camera,+2,0,0
	
	If KeyDown(203) TurnEntity player,0,2,0
	If KeyDown(205) TurnEntity player,0,-2,0
	
	If KeyDown(200) MoveEntity player,0,0,sp
	If KeyDown(208) MoveEntity player,0,0,-sp
	
	CheckBox()
	
	UpdateWorld
	RenderWorld
	Flip
Wend

FreeEntity Building
FreeEntity box

End

Function ResizeMesh(mesh,width#,height#,depth#)
   
ScaleMesh mesh,1/MeshWidth#(mesh)*width#,1/MeshHeight#(mesh)*height#,(1/MeshDepth#(mesh))*depth#

End Function

Function CheckBox()

If Distance(Player,Box) < 2 Then
	RuntimeError Name$ + "Won!!!!!"
EndIf

End Function

Function Distance(Entity1,Entity2)

Entity1Pos = EntityZ(Entity1) + EntityY(Entity1) + EntityX(Entity1)

Entity2Pos = EntityZ(Enitiy2) + EntityY(Entity2) + EntityX(Entity2)

Return Entity1Pos - Entity2Pos

End Function


You don't need the "Distance" function, just use EntityDistance.

Not sure if this'll help but why are you using approximate distances?

you can replace all of this
Function CheckBox()

If Distance(Player,Box) < 2 Then
	RuntimeError Name$ + "Won!!!!!"
EndIf

End Function

Function Distance(Entity1,Entity2)

Entity1Pos = EntityZ(Entity1) + EntityY(Entity1) + EntityX(Entity1)

Entity2Pos = EntityZ(Enitiy2) + EntityY(Entity2) + EntityX(Entity2)

Return Entity1Pos - Entity2Pos

End Function




with ..


Function CheckBox()

If entityDistance(Player,Box) < 2 Then
	RuntimeError Name$ + "Won!!!!!"
EndIf



Also, instead of your resize mesh function just use FITMESH.

Not sure if this'll help just thought I'd point out a few things

How'd you get your code in that scroll box?

(codebox)

(/codebox)


[] instead of ()

I didn't know there was an EntityDistance!
Thanks