Weird NaN problem

Blitz3D Forums/Blitz3D Programming/Weird NaN problem

Hello,

I am trying to make some "borders" for my level. I am using infinite planes to make them. I had to rotate them to put them in a way that they form a square around the area I want the player to be in. Everything was working fine until I added these infinite planes. Now, whenever I turn the ship around the screen goes black and values for the player's X and Z position become NaNs. Has anyone experienced a similar problem? Here's the code:
Function CreateBoundingBox()

border_left = CreatePlane()
RotateEntity border_left,0,180,90
PositionEntity border_left,-1200,0,-1200
EntityType border_left,2
EntityAlpha border_left,0.5

border_right = CreatePlane()
RotateEntity border_right,0,180,90
PositionEntity border_right,1200,0,1200
EntityType border_right,2
EntityAlpha border_right,0.5

border_north = CreatePlane()
RotateEntity border_north,90,180,0
PositionEntity border_north,-1200,0,1200
EntityType border_north,2
EntityAlpha border_north,0.5

border_south = CreatePlane()
RotateEntity border_south,90,180,0
PositionEntity border_south,1200,0,-1200
EntityType border_south,2
EntityAlpha border_south,0.5

End Function

And this is the player control code:

Collisions 1,2,2,1 ;player to border


While Not KeyDown(1)

If KeyDown(203) ;left
TurnEntity pivot,0,1,0
player_angle# = player_angle#+1
If player_angle#>30 Then player_angle# = 30
RotateEntity player, 0,player_angle#,0
;rotación de la cámara
roll#=roll# -1
If roll# <-30 Then roll# =-30
EndIf

If KeyDown(205) ;right
TurnEntity pivot, 0,(-1),0
;rotación de la nave
player_angle# = player_angle#-1
If player_angle#<-30 Then player_angle# =-30
RotateEntity player, 0,player_angle#,0
;rotación de la cámara
roll#=roll#+1
If roll# >30 Then roll# =30
EndIf

;wireframe!
If KeyHit(17) ; "W" pressed
wire = Not wire
WireFrame wire
EndIf


If Not KeyDown(205)
If Not KeyDown(203)
If roll# > 0 Then roll# = roll#-1
If roll# < 0 Then roll# = roll#+1
If player_angle# > 0 Then player_angle#=player_angle# -1
If player_angle# < 0 Then player_angle#=player_angle# +1
EndIf
EndIf

RotateEntity player,0,player_angle#,0

If KeyDown(30) ;"a" is pressed
player_speed# = player_speed# +0.01
If player_speed# >= 3 Then player_speed# =3
EndIf

If KeyDown(44) ; "Z" is pressed
player_speed# = player_speed# -0.01
If player_speed# <= 0.40 Then player_speed# =0.40
EndIf

;forward movement

MoveEntity pivot ,0,0,player_speed#


;make the camera point to the player
PointEntity camera,player,roll#

UpdateWorld
RenderWorld


Text 0,0,Str(player_speed#)
Text 0,25,Str(player_angle#)
Text 0,50,"X: " + Str(EntityX(pivot))
Text 50,0,"Z: " + Str(EntityZ(pivot))

Flip
Wend


Any suggestions on what might be wrong?

Skycube

I was having much the same problem when constantly unparenting, parenting and moving the same pivot over and over.

entityposition pivot,0,0,0
entityscale pivot,1,1,1

before doing anything else with the pivot seemed to sort it

what Graphics Card and CPU do you have? (I am currently fighting NaN problems too, see the other thread)

Nice find. You guys should try this. It is something to do with how the system detects plane colisions. I was not sure you were setting up the planes correctly so I changed that. However what changes I did make have not resolved the issue, though it probably changes the dynamics slightly.

BTW to see the problem keep yawing in the same direction while moving. (if you cap the box it is even worse).

Function CreateBoundingBox()
 
border_left = CreatePlane() 
EntityColor border_left,0,200,0 
RotateEntity border_left,-90,90,0 
PositionEntity border_left,-1200,0,0 
EntityType border_left,2 
;EntityAlpha border_left,0.5 

border_right = CreatePlane() 
EntityColor border_right,200,200,0 
RotateEntity border_right,-90,-90,0 
PositionEntity border_right,1200,0,0 
EntityType border_right,2 
;EntityAlpha border_right,0.5 

border_north = CreatePlane() 
EntityColor border_north,0,0,200 
RotateEntity border_north,-90,0,0 
PositionEntity border_north,0,0,1200 
EntityType border_north,2 
;EntityAlpha border_north,0.5 

border_south = CreatePlane() 
EntityColor border_south,200,0,200 
RotateEntity border_south,90,0,0 
PositionEntity border_south,0,0,-1200 
EntityType border_south,2 
ResetEntity border_south 
;EntityAlpha border_south,0.5 

End Function 

;And this is the player control code: 

Graphics3D 640,480,0,2

camera=CreateCamera()
CameraRange camera,1,2000

createboundingbox()

pivot=CreatePivot()
EntityType pivot,1
player=CreateCone(12,1,pivot)
EntityColor player,255,0,0
RotateMesh player,90,0,0

Collisions 1,2,2,1 ;player to border 

While Not KeyDown(1) 

If KeyDown(203) ;left 
TurnEntity pivot,0,1,0 
player_angle# = player_angle#+1 
If player_angle#>30 Then player_angle# = 30 
RotateEntity player, 0,player_angle#,0 
;rotación de la cámara 
roll#=roll# -1 
If roll# <-30 Then roll# =-30 
EndIf 

If KeyDown(205) ;right 
TurnEntity pivot, 0,(-1),0 
;rotación de la nave 
player_angle# = player_angle#-1 
If player_angle#<-30 Then player_angle# =-30 
RotateEntity player, 0,player_angle#,0 
;rotación de la cámara 
roll#=roll#+1 
If roll# >30 Then roll# =30 
EndIf 


;wireframe! 
If KeyHit(17) ; "W" pressed 
wire = Not wire 
WireFrame wire 
EndIf 

If Not KeyDown(205) 
If Not KeyDown(203) 
If roll# > 0 Then roll# = roll#-1 
If roll# < 0 Then roll# = roll#+1 
If player_angle# > 0 Then player_angle#=player_angle# -1 
If player_angle# < 0 Then player_angle#=player_angle# +1 
EndIf 
EndIf 

RotateEntity player,0,player_angle#,0 

If KeyDown(30) ;"a" is pressed 
player_speed# = player_speed# +0.01 
If player_speed# >= 3 Then player_speed# =3 
EndIf 

If KeyDown(44) ; "Z" is pressed 
player_speed# = player_speed# -0.01 
If player_speed# <= 0.40 Then player_speed# =0.40 
EndIf 

;forward movement 

MoveEntity pivot ,0,0,player_speed# 

;make the camera point to the player 
PointEntity camera,player,roll# 

UpdateWorld 
RenderWorld 


Text 0,0, player_speed# 
Text 0,12,player_angle# 
Text 0,36,"X: " + EntityX(pivot)
Text 0,48,"Z: " + EntityZ(pivot)
Text 0,60,EntityYaw(pivot)
Text 0,72,CountCollisions(pivot)

Flip 
Wend 




So to resolve the issue I suggest you use separate cubes to build the box, or perhaps just one flipped cube (or indeed anything other than planes :). Something along the lines of

Function CreateBoundingBox(size#,alpha#)
cube=CreateCube()
FlipMesh(cube)
EntityColor cube,255,255,0
ScaleMesh cube,size,size,size
EntityType cube,2
EntityAlpha cube,alpha
Return cube
End Function 

; or...............

Function CreateBoundingBox(size#,alpha#)

ent=CreateCube()
ScaleMesh ent,size,0.1,size
EntityType ent,2
EntityAlpha ent,alpha
 
border_left = ent 
EntityColor border_left,0,200,0 
RotateEntity border_left,-90,90,0 
PositionEntity border_left,-size,0,0 

border_right = CopyEntity(ent) 
EntityColor border_right,200,200,0 
RotateEntity border_right,-90,-90,0 
PositionEntity border_right,size,0,0 

border_north = CopyEntity(ent)
EntityColor border_north,0,0,200 
RotateEntity border_north,-90,0,0 
PositionEntity border_north,0,0,size 

border_south = CopyEntity(ent)
EntityColor border_south,200,0,200 
RotateEntity border_south,90,0,0 
PositionEntity border_south,0,0,-size 
End Function 



Whats a NaN? I feel un-enlightened :(

NaN means Not a Number.

Ahhh

You usually get NaN's when you do something mathematically funny. Such as trying to divide by zero or square root a negative number. So I'd start looking for those first, as everytime I get NaN's it is because of this.

Hi everyone and thanks for your suggestions. Sorry I took so long in replying. I tried the FlipMesh method suggested by DJWoodgate and it worked fine. Thanks!