general 3d game errors

Blitz3D Forums/Blitz3D Beginners Area/general 3d game errors

Eren(Posted 2014) [#1]
I have many problems with a simple 3d game I'm making, but ill only mention the main ones. The others, I can probably fix.

The errors:

- When I try to print text in the 'while' loop, it, on occasion, shows up for a tiny bit, then goes away. other times it doesn't even show up at all. This problem started to occur before I put in the 3d commands in.

- How can I add collisions to the ground, so whenever I look at the floor and move forward/backward, I don't fly through it, and instead I just keep moving forward? I tried using collisions, but they either did nothing, or made the game work improperly. I tried using a bit of code from another of my topic's replys, but whever you looked at the ground and moved forwards, you moved 2x as fast. Someone then mentioned me in that topic that 'delta timing' or something will fix it. I really don't know what it is.

I have the code here:

Graphics3D 640,480,32,2
SetBuffer BackBuffer()
HidePointer

;Constants
Global Pcoll = 1
Global Tcoll = 2

;Textures
Global GrassTexture = LoadTexture("grass_texture.jpg")
Global SkyTexture = LoadTexture("sky.jpg")

;Objects/Entities
Global Ground = CreatePlane()
Global Sky = CreateSphere()
Global Camera = CreateCamera()
AmbientLight 500,500,500

;Texturing
EntityTexture Ground,GrassTexture
EntityTexture Sky,SkyTexture

;Object/Entity Positions
PositionEntity Camera,0,2,1
PositionEntity Ground,0,0,0
PositionEntity Sky,0,200,0

;Object/Entity Sizes
ScaleEntity Sky,500,500,500

;Other Stuff
FlipMesh Sky

;Types
Type MeleeType
Field Damage
Field Health%
Field Range
End Type

Type RangedType
Field Damage
Field Health%
Field Range
End Type

Type PlayerType
Field Health%
Field WaterLevel%
Field FoodLevel%
Field Status$
Field BodyTemperature
End Type

Player.PlayerType = New PlayerType
Player\Health% = 100
Player\WaterLevel% = 100
Player\FoodLevel% = 100
Player\Status$ = "Healthy"
Player\BodyTemperature = 37

;Main Loop
While Not KeyHit(1)

Text 0,0, "Body Temperature: "+Player\BodyTemperature+" Degrees Celsius"
Text 0,30, "Health: "+Player\Health%
Text 0,45, "Thirst: "+Player\WaterLevel%
Text 0,60, "Hunger: "+Player\FoodLevel%
Text 0,15, "Status: "+Player\Status$

mxs# = mxs#+MouseXSpeed()/4
mys# = mys#+MouseYSpeed()/4

If mxs# < 0 Then mxs# = 360
If mxs# > 360 Then mxs# = 0

If mys# > 80 Then mys# = 80
If mys# < -80 Then mys# = -80

RotateEntity Camera,mys#,-mxs#,0
MoveMouse 400,300

If KeyDown(17) Then MoveEntity Camera,0,0,0.1
If KeyDown(30) Then MoveEntity Camera,-0.1,0,0
If KeyDown(31) Then MoveEntity Camera,0,0,-0.1
If KeyDown(32) Then MoveEntity Camera,0.1,0,0

UpdateWorld()
RenderWorld()

Flip
Wend
End

Obviously you can't run it, since I have some commands that load up texture files. But if you want you can get your own pictures and/or rename some pictures to the names in the code for it to work.


Gauge(Posted 2014) [#2]
I'm not sure on the rest, however put the text commands between the renderworld, and flip.

As far as the camera issue, you should use a camera attached to a mesh. Use the mesh for collisions, as I do not believe a camera can do collisions. Rotate the camera independtly to look directions, and move the mesh on its own, and the camera will follow correctly....perhaps. Not sure if this is useful, but there is a way to move/rotate a child entity as a world, or as a child.


Matty(Posted 2014) [#3]
Camera can do collision fine. Have a look at the castle example in mak folder in blitz3d samples. You are right. ...timing is what is required to fix your walking too fast issue.


RemiD(Posted 2014) [#4]
->Text() must be put after renderworld() and before Flip()
->Updateworld() is useless in your code
->to understand how collisions between "colliders" (emitters) and "collidables" (receivers) work, take a look at this example :
http://www.blitzbasic.com/codearcs/codearcs.php?code=3141
if you use blitz3d collisions system, a collider can only be an ellipsoid (a sphere shape, in this case you must turn/move the ellipsoid) or a pivot parent of several ellipsoids (several sphere shapes positionned as you want around the parent pivot which follow the parent pivot, in this case you must turn/move the parent pivot). Collidables can have any shape you want (meshes), preferably low tris.
->to understand a way to have an automatic adjustement of the speed of the turns/moves so that it looks the same whatever the complexity of the scene and whatever the computer hardware, take a look at this example :
http://www.blitzbasic.com/codearcs/codearcs.php?code=2916