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). 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 |
| ||
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! |