MiniB3d for FreeBasic
Re: MiniB3d for FreeBasic
The cube by default should go from -1 to 1 in each axis, so, assuming that you haven't moved the plane, by default the cube should be halfway above, halfway below the plane. Lowering it by 0.02 is not enough to make it go totally below the plane. What happens if you replace that "-0.02" with "-1.01"?
Re: MiniB3d for FreeBasic
Yes, it works with value -1.01, although it is too fast in this case.
But you gave me another idea: originally this cube is scaled up to a column when I created it:
ScaleEntity teleport.image,1,12,1
and I move it so:
if entityy#(teleport.image)-0.02>-12 then
positionentity teleport.image,entityx#(teleport.image),entityy#(teleport.image)-0.02,entityz#(teleport.image)
But you mentioned in your answer: "The cube by default should go from -1 to 1 in each axis", so I changed this:
if entityy#(teleport.image)-0.02>-13 then ... because the cube goes 1 in Y axis too, I added this +1 to the value. So, I can move it smoothly.
But there are an interesting bug: when I move above the lowered cube, the camera jumps up and stay in this position.
What could be the reason for this? Before I set up a collision with these wall objects:
collisions 1,3,2,2 'Collisions between camera and walls
Maybe this is what causes the phenomenon? How can I avoid this?
But you gave me another idea: originally this cube is scaled up to a column when I created it:
ScaleEntity teleport.image,1,12,1
and I move it so:
if entityy#(teleport.image)-0.02>-12 then
positionentity teleport.image,entityx#(teleport.image),entityy#(teleport.image)-0.02,entityz#(teleport.image)
But you mentioned in your answer: "The cube by default should go from -1 to 1 in each axis", so I changed this:
if entityy#(teleport.image)-0.02>-13 then ... because the cube goes 1 in Y axis too, I added this +1 to the value. So, I can move it smoothly.
But there are an interesting bug: when I move above the lowered cube, the camera jumps up and stay in this position.
What could be the reason for this? Before I set up a collision with these wall objects:
collisions 1,3,2,2 'Collisions between camera and walls
Maybe this is what causes the phenomenon? How can I avoid this?
Re: MiniB3d for FreeBasic
It's impossible to figure what's going on without seeing the code. You didn't mention any command that moves the camera, nor the entity type you used for camera, walls, and other objects, nor the geometry of the walls, so I have no idea of what is going on in your program.
Re: MiniB3d for FreeBasic
It seems, I don't understand the working of positionentity command either:
In my game I move down the camera when the player dies:
then when I reload the level with the Space button, I would like set the Y position of the camera to 0, because it is now at -0.2:
But this code sets the camera at lower negative level, e.g. -3. ... just like this code:
and I don't know, what is wrong with these? How can I solve this problem?
In my game I move down the camera when the player dies:
Code: Select all
if entityy#(kamera)-0.02>entityy#(ground)+0.8 then 'entityy#(ground)=-1
if timer-movedowntime>0.02 then
positionentity kamera,entityx#(kamera),entityy#(kamera)-0.02,entityz#(kamera) : movedowntime=timer
end if
end if
Code: Select all
if multikey(sc_space) then
clearlevel()
while entityy#(kamera)+0.1<entityy#(ground)-0.8
positionentity kamera,entityx#(kamera),entityy#(kamera)+0.1,entityz#(kamera)
wend
buildlevel(numoflevel)
end if
Code: Select all
positionentity kamera,entityx#(kamera),0,entityz#(kamera)
Re: MiniB3d for FreeBasic
That's simple : you compare the vertical position of the camera with the vertical position of the ground, but in one case you add 0.8 to the ground coordinate (meaning above the ground), in the other you subtract 0.8, meaning below the ground. So, the positionentity command is likely never executed when you try to restore the camera position
Re: MiniB3d for FreeBasic
But in the first case, when I move the camera under the ground, the values are:
entityy#(ground) whose value is -1 + 0.8 = -0.2
And then I would like lift up this -0.2 camera value back to 0. But when I execute the positionentity command, it decreases the Y value to greater negative value instead of resetting to 0.
And this command doesn't work either:
Maybe entity values are relative to something other?
entityy#(ground) whose value is -1 + 0.8 = -0.2
And then I would like lift up this -0.2 camera value back to 0. But when I execute the positionentity command, it decreases the Y value to greater negative value instead of resetting to 0.
And this command doesn't work either:
Code: Select all
positionentity kamera,entityx#(kamera),0,entityz#(kamera)
Re: MiniB3d for FreeBasic
They are relative to something else if the entity has a parent: in that case they are relative to parent's position
Re: MiniB3d for FreeBasic
And is it possible that the entity is relative to values of itself?
Because in my program I build the game level from a Data structure like this:
But there are two problem based on this:
1. When I run the game first, the entityx and entityz values of the camera are 61.87798 . But after the player died and I restart the game and rebuild it from the Data structure, the values always change to 128.
What is the reason of this difference?
2. Why change the value of entityx of the camera when I moving with the player with this code? Because I just change the entityz and entityy in moveentity and turnentity commands:
Because in my program I build the game level from a Data structure like this:
Code: Select all
level1:
data 4 'width
data 4 'height
data 0,0,0,0
data 0,2,0,4
data 0,0,0,0
data 0,0,0,3
dim as ubyte pwidth,pheight,value,px,pz
restore level1
read pwidth
read pheight
px=1 : pz=1
for i as ubyte=1 to pheight
for j as ubyte=1 to pwidth
read value
select case value
case 3 'player
positionentity kamera,px*32,0,pz*32
end select
px+=1
if j=pwidth then
px=1 : pz+=1
end if
next j
next i
1. When I run the game first, the entityx and entityz values of the camera are 61.87798 . But after the player died and I restart the game and rebuild it from the Data structure, the values always change to 128.
What is the reason of this difference?
2. Why change the value of entityx of the camera when I moving with the player with this code? Because I just change the entityz and entityy in moveentity and turnentity commands:
Code: Select all
if multikey(sc_up) then
if multikey(sc_r) then 'Run:
moveentity kamera,0,0,2*player.speed*dt
else
moveentity kamera,0,0,player.speed*dt
end if
end if
if multikey(sc_down) then
moveentity kamera,0,0,-1*player.speed*dt
end if
if multikey(sc_left) then
turnentity kamera,0,4*player.speed*dt,0
end if
if multikey(sc_right) then
turnentity kamera,0,-4*player.speed*dt,0
end if
Re: MiniB3d for FreeBasic
Yes, if you use MoveEntity,And is it possible that the entity is relative to values of itself?
PositionEntity doesn't take in account the current position of the entity, only of its parent (if the entity has a parent). MoveEntity does
So, "PositionEntity ent,0,0,1" will place the entity at coordinates 0,0,1 (relative to its parent), no matter where the entity is. Repeating the command more than once will be useless. Instead "MoveEntity ent,0,0,1" will move the entity forward by one from its current position, and repeating the command several times will cause the entity to move further
So, a command like ""PositionEntity ent,0,0,EntityZ(ent)+1" is more or less equivalent to "MoveEntity ent,0,0,1" (not exactly the same, because MoveEntity takes rotation in account too)
I cannot test your code if you give only small parts of it, since I don't know if there are other commands somewhere else affecting the camera, nor how it has been created. You should make an example than can be compiled on its own if you want me to test it
Re: MiniB3d for FreeBasic
"I cannot test your code if you give only small parts of it, since I don't know if there are other commands somewhere else affecting the camera, nor how it has been created. You should make an example than can be compiled on its own if you want me to test it"
Here is a smaller code based on my whole program. The main problem is when you restart it with pressing of SPACE button after you moving a bit, the position of the camera will be different. Although the Entityx of the camera here is always 96, in my program it is different at the start of the program and when the user restart it.
Here is a smaller code based on my whole program. The main problem is when you restart it with pressing of SPACE button after you moving a bit, the position of the camera will be different. Although the Entityx of the camera here is always 96, in my program it is different at the start of the program and when the user restart it.
Code: Select all
#Include "openb3d.bi"
#include "fbgfx.bi"
Using FB
const sw=800 : const sh=600
const pxunit=32 : const pzunit=32
ScreenRes sw,sh,32,,&h10002
Graphics3d sw,sh
dim shared as any ptr camera,column,sun,imagetohud,hudimg,hudstringtex
redim shared as any ptr wall(4)
Sub loadlevel()
dim as ubyte pwidth,pheight,value,px,pz
restore level1
read pwidth
read pheight
px=1 : pz=1
wall(0)=CreateCube()
PositionEntity wall(0),1,0,1
ScaleEntity wall(0),pwidth*pxunit,1,1
wall(1)=CreateCube()
PositionEntity wall(1),1,0,pheight*pzunit
ScaleEntity wall(1),pwidth*pxunit,1,1
wall(2)=CreateCube()
PositionEntity wall(2),1,0,1
ScaleEntity wall(2),1,1,pheight*pzunit
wall(3)=CreateCube()
PositionEntity wall(3),pwidth*pxunit,0,1
ScaleEntity wall(3),1,1,pheight*pzunit
for i as ubyte=1 to pheight
for j as ubyte=1 to pwidth
read value
select case value
case 2 'a column
column=CreateCylinder()
positionentity column,px*pxunit,0,pz*pzunit
ScaleEntity column,1,4,1
case 3 'player position
positionentity camera,px*pxunit,0,pz*pzunit
end select
px+=1
if j=pwidth then
px=1 : pz+=1
end if
next j
next i
end sub
camera=CreateCamera()
sun=CreateLight()
var ground=CreatePlane()
Dim gtex as any ptr=ImageCreate(64,64,RGB(0,128,0))
EntityTexture ground,gtex
ScaleEntity ground,1,50,1
ScaleTexture gtex,1,50
MoveEntity ground,0,-1,0
EntityOrder ground,1
imagetohud=imagecreate(128,32,32)
hudimg=CreateSprite(camera)
MoveEntity hudimg,3.8,2.7,5
EntityOrder hudimg,-1
hudstringtex=CreateTexture(128,32)
EntityTexture hudimg,hudstringtex
loadlevel()
Do
if multikey(sc_space) then 'Deleting and rebuilding of the game elements:
FreeEntity column
for i as ubyte=0 to 3
FreeEntity wall(i)
next i
loadlevel()
end if
if multikey(sc_up) then
moveentity camera,0,0,2
end if
if multikey(sc_down) then
moveentity camera,0,0,-2
end if
if multikey(sc_left) then
turnentity camera,0,2,0
end if
if multikey(sc_right) then
turnentity camera,0,-2,0
end if
Line imagetohud,(0,0)-(511,31),RGB(150,10,0),BF
draw string imagetohud,(1,1),"Cam. EX: "+str(Entityx#(camera))
BufferToTex hudstringtex,imagetohud,1
updateworld
renderworld
Flip
Sleep 10
Loop Until MultiKey(sc_escape)
level1:
data 4 'width
data 4 'height
data 0,0,0,0
data 0,2,0,0
data 0,0,3,0
data 0,0,0,0
Re: MiniB3d for FreeBasic
I don't understand: you mean that, in this smaller program, the bug doesn't happen, while in your real program it happens?
Also, after the line:
Code: Select all
positionentity camera,px*pxunit,0,pz*pzunit
Code: Select all
rotateentity camera,0,0,0
Re: MiniB3d for FreeBasic
Maybe I found the location of the bug(?) in my program:
the UpdateWorld command is somehow disturbs the Entityx# etc. values of the camera after the first creating of the level, because it sets these to 61. ... instead of 128 in my Data structure.
So, when I checked these entity values before using UpdateWorld, everything is OK, as well as after I restart the level. But when I start the program first time and check these values, totally different from what I expected.
The program logic as follows:
creating the camera
using of loadlevel(), which set the camera position, too.
Do 'the main game loop:
doing game stuff
updateworld
renderworld
Flip
Loop Until MultiKey(sc_escape)
What could be the cause this bug? Is this a bug at all, or rather I do something wrong?
the UpdateWorld command is somehow disturbs the Entityx# etc. values of the camera after the first creating of the level, because it sets these to 61. ... instead of 128 in my Data structure.
So, when I checked these entity values before using UpdateWorld, everything is OK, as well as after I restart the level. But when I start the program first time and check these values, totally different from what I expected.
The program logic as follows:
creating the camera
using of loadlevel(), which set the camera position, too.
Do 'the main game loop:
doing game stuff
updateworld
renderworld
Flip
Loop Until MultiKey(sc_escape)
What could be the cause this bug? Is this a bug at all, or rather I do something wrong?
Re: MiniB3d for FreeBasic
Sounds like an issue with collisions management.
Do you use collisions? In case you might need to use the command ResetEntity
Do you use collisions? In case you might need to use the command ResetEntity
Re: MiniB3d for FreeBasic
Thank you, Angros47, your advice works!
I put the command ResetEntity at the correct places and now the player's position is always OK.
There are a - hopefully - last problem in my program, although it is only an aesthetic issue: I would like draw a background for the texts, but I use method results an ugly rectangle which is correct at the top, but the lower half is mixed with different colors.
This is my code for this, but I would like a correct size rectangle around the text, without unnecessary parts:

I put the command ResetEntity at the correct places and now the player's position is always OK.
There are a - hopefully - last problem in my program, although it is only an aesthetic issue: I would like draw a background for the texts, but I use method results an ugly rectangle which is correct at the top, but the lower half is mixed with different colors.
This is my code for this, but I would like a correct size rectangle around the text, without unnecessary parts:
Code: Select all
#Include "openb3d.bi"
#include "fbgfx.bi"
dim shared as any ptr camera,sun,imagetohud,hudimg,hudstringtex
Using FB
ScreenRes 800,600,32,,&h10002
Graphics3d 800,600
imagetohud=imagecreate(128,16,32)
hudimg=CreateSprite(camera)
MoveEntity hudimg,3.8,2.7,5
EntityOrder hudimg,-1
hudstringtex=CreateTexture(128,32)
EntityTexture hudimg,hudstringtex
camera=CreateCamera()
sun=CreateLight()
While Not MultiKey(sc_escape)
Line imagetohud,(0,0)-(511,15),RGB(150,10,0),BF
draw string imagetohud,(1,1),"Hello world!"
BufferToTex hudstringtex,imagetohud,1
RenderWorld
Flip
Wend