Problems with Ray Diaz's Beginners Tutorials

Blitz3D Forums/Blitz3D Beginners Area/Problems with Ray Diaz's Beginners Tutorials

Hi all,

I follow the 3d tutorial -Tutorial 3- battle003. (The following media files also come from that tutorial)
My test files could be downloaded here!

;graphics
Graphics3D 800,600
SetBuffer BackBuffer()

;globals
Global floor1, nacar
Global x#,y#,z#,terra_y#
Global kit, ttShoppe

;collision groups
Global SCENERY = 1 
Global PLAYER = 2
Global PROPS = 4
Global CARPET = 5
	
;light
Global light = CreateLight()
RotateEntity light,90,0,90

;camera pivot
camera_pivot = CreatePivot()
EntityRadius camera_pivot,1.4
EntityType camera_pivot, PLAYER

;camera
Global camera = CreateCamera(camera_pivot)
CameraRange camera,1,10000
CameraFogMode camera,1
CameraFogRange camera,60,200

;sky
Global sky = CreateSphere(16,camera_pivot)
FlipMesh sky
ScaleEntity sky,100,100,100
PositionEntity sky,0,50,0
sky_tex = LoadTexture("sky.bmp")
EntityTexture sky,sky_tex

;terrain
Global terrain = LoadTerrain("height2.jpg")
TerrainDetail terrain,2500,True
ScaleEntity terrain,3,15,3
PositionEntity terrain,-1000,0,-530
ter_tex = LoadTexture("mossyground.bmp")
EntityTexture terrain, ter_tex
EntityRadius terrain,0.2
EntityType terrain, SCENERY

; Weapon 
Global weapon2 = LoadMesh("gloc.3ds",camera_pivot)
weapon_tex2 = LoadTexture("glocmap.jpg")
EntityTexture weapon2,weapon_tex2
RotateEntity weapon2,12,170,14
ScaleEntity weapon2,0.01,0.01,0.01
PositionEntity weapon2,0.01,0.01,0.01
PositionEntity weapon2,1,-1,1.5
EntityOrder weapon2,-1

; a floor
cube_tile = LoadTexture("Floor.jpg")
floor1 = CreateCube()
ScaleEntity floor1,8,0.06,13
ScaleTexture cube_tile,.5,.5
EntityTexture floor1,cube_tile
EntityType floor1,CARPET
EntityRadius floor1,.4
PositionEntity floor1,10,6,120

; More floors
floor2 = CopyEntity(floor1)
floor3 = CopyEntity(floor1)
floor4 = CopyEntity(floor1)
PositionEntity floor2,-100,6,120
PositionEntity floor3,100,6,120
PositionEntity floor4,0,6,0

; kitchen
kit = LoadMesh("weapshop.3ds")
kit_tex = LoadTexture("kitchen.jpg")
EntityTexture kit,kit_tex
EntityType kit,PROPS
EntityRadius kit,1.10
PositionEntity kit,10,6.5,128
ScaleEntity kit,0.08,0.08,0.08

; other stuff
ttShoppe = LoadMesh("shop.3ds")
PositionEntity ttShoppe, 10,6.5,112
RotateEntity ttShoppe, 0,180,0
ScaleEntity ttShoppe, 0.08,0.08,0.08
ttShoppe_tex = LoadTexture("ttshop.jpg")
EntityTexture ttShoppe, ttshoppe_tex
EntityType ttShoppe,PROPS
EntityRadius ttShoppe,1.10

nacar = LoadMesh("pearlank.b3d")
nacar_tex = LoadTexture("eggo2.jpg",67)
EntityTexture nacar,nacar_tex
PositionEntity nacar ,10,6.4,120
ScaleEntity nacar,0.005,0.005,0.005
EntityType nacar,PROPS
EntityRadius nacar,1

;position the cammera
PositionEntity camera_pivot,10,5.6,120

;collision handling
Collisions CARPET, SCENERY,2,1
Collisions PLAYER, PROPS, 2,1

;main loop
While Not KeyHit(1)
	If KeyDown(200) MoveEntity camera_pivot, 0,0,0.2
	If KeyDown(208) MoveEntity camera_pivot, 0,0,-.2
	If KeyDown(203) TurnEntity camera_pivot, 0,2,0
	If KeyDown(205) TurnEntity camera_pivot, 0,-2,0
	
	x# = EntityX(camera_pivot)
	y# = EntityY(camera_pivot)
	z# = EntityZ(camera_pivot)

	touchGround(floor1)
	touchGround(floor2)
	touchGround(floor3)
	touchGround(floor4)

	TurnEntity nacar,0.5,0.5,0
		
	UpdateWorld
	
	terra_y# = TerrainY(terrain,x#,y#,z#)+1.6
	PositionEntity camera_pivot,x#,terra_y#,z#
	
	RenderWorld
	
	Text 10,10, "X= "+x#
	Text 10,25, "Y= "+y#
	Text 10,40, "Z= "+z#
	
	Flip
Wend

Function touchGround(n$)
	If Not EntityCollided(n$,SCENERY)
		PositionEntity(n$, EntityX(n$), EntityY(n$) -0.01, EntityZ(n$))
	EndIf
End Function

End


Questions:
-------------
1. When I run the program, I STILL could pass through wall of house, even I have set the collisons command.
(Collisions PLAYER, PROPS, 2,1). Why? (I tried to run the sample program provided and still could pass through wall!!!)

2. According to the tutorial,
terra_y# = TerrainY(terrain,x#,y#,z#)+1.6
PositionEntity camera_pivot,x#,terra_y#,z#
MUST be after "UpdateWorld" command.
However, according to B3d Manual, "UpdateWorld" is used for collision checking.
So, I tried to move these 2 statements before "UpdateWorld" command as follows:

;graphics
Graphics3D 800,600
SetBuffer BackBuffer()

;globals
Global floor1, nacar
Global x#,y#,z#,terra_y#
Global kit, ttShoppe

;collision groups
Global SCENERY = 1 
Global PLAYER = 2
Global PROPS = 4
Global CARPET = 5
	
;light
Global light = CreateLight()
RotateEntity light,90,0,90

;camera pivot
camera_pivot = CreatePivot()
EntityRadius camera_pivot,1.4
EntityType camera_pivot, PLAYER

;camera
Global camera = CreateCamera(camera_pivot)
CameraRange camera,1,10000
CameraFogMode camera,1
CameraFogRange camera,60,200

;sky
Global sky = CreateSphere(16,camera_pivot)
FlipMesh sky
ScaleEntity sky,100,100,100
PositionEntity sky,0,50,0
sky_tex = LoadTexture("sky.bmp")
EntityTexture sky,sky_tex

;terrain
Global terrain = LoadTerrain("height2.jpg")
TerrainDetail terrain,2500,True
ScaleEntity terrain,3,15,3
PositionEntity terrain,-1000,0,-530
ter_tex = LoadTexture("mossyground.bmp")
EntityTexture terrain, ter_tex
EntityRadius terrain,0.2
EntityType terrain, SCENERY

; Weapon 
Global weapon2 = LoadMesh("gloc.3ds",camera_pivot)
weapon_tex2 = LoadTexture("glocmap.jpg")
EntityTexture weapon2,weapon_tex2
RotateEntity weapon2,12,170,14
ScaleEntity weapon2,0.01,0.01,0.01
PositionEntity weapon2,0.01,0.01,0.01
PositionEntity weapon2,1,-1,1.5
EntityOrder weapon2,-1

; a floor
cube_tile = LoadTexture("Floor.jpg")
floor1 = CreateCube()
ScaleEntity floor1,8,0.06,13
ScaleTexture cube_tile,.5,.5
EntityTexture floor1,cube_tile
EntityType floor1,CARPET
EntityRadius floor1,.4
PositionEntity floor1,10,6,120

; More floors
floor2 = CopyEntity(floor1)
floor3 = CopyEntity(floor1)
floor4 = CopyEntity(floor1)
PositionEntity floor2,-100,6,120
PositionEntity floor3,100,6,120
PositionEntity floor4,0,6,0

; kitchen
kit = LoadMesh("weapshop.3ds")
kit_tex = LoadTexture("kitchen.jpg")
EntityTexture kit,kit_tex
EntityType kit,PROPS
EntityRadius kit,1.10
PositionEntity kit,10,6.5,128
ScaleEntity kit,0.08,0.08,0.08

; other stuff
ttShoppe = LoadMesh("shop.3ds")
PositionEntity ttShoppe, 10,6.5,112
RotateEntity ttShoppe, 0,180,0
ScaleEntity ttShoppe, 0.08,0.08,0.08
ttShoppe_tex = LoadTexture("ttshop.jpg")
EntityTexture ttShoppe, ttshoppe_tex
EntityType ttShoppe,PROPS
EntityRadius ttShoppe,1.10

nacar = LoadMesh("pearlank.b3d")
nacar_tex = LoadTexture("eggo2.jpg",67)
EntityTexture nacar,nacar_tex
PositionEntity nacar ,10,6.4,120
ScaleEntity nacar,0.005,0.005,0.005
EntityType nacar,PROPS
EntityRadius nacar,1

;position the cammera
PositionEntity camera_pivot,10,5.6,120

;collision handling
Collisions CARPET, SCENERY,2,1
Collisions PLAYER, PROPS, 2,1

;main loop
While Not KeyHit(1)
	If KeyDown(200) MoveEntity camera_pivot, 0,0,0.2
	If KeyDown(208) MoveEntity camera_pivot, 0,0,-.2
	If KeyDown(203) TurnEntity camera_pivot, 0,2,0
	If KeyDown(205) TurnEntity camera_pivot, 0,-2,0
	
	x# = EntityX(camera_pivot)
	y# = EntityY(camera_pivot)
	z# = EntityZ(camera_pivot)

	terra_y# = TerrainY(terrain,x#,y#,z#)+1.6
	PositionEntity camera_pivot,x#,terra_y#,z#

	touchGround(floor1)
	touchGround(floor2)
	touchGround(floor3)
	touchGround(floor4)

	TurnEntity nacar,0.5,0.5,0
		
	UpdateWorld
	
	
	RenderWorld
	
	Text 10,10, "X= "+x#
	Text 10,25, "Y= "+y#
	Text 10,40, "Z= "+z#
	
	Flip
Wend

Function touchGround(n$)
	If Not EntityCollided(n$,SCENERY)
		PositionEntity(n$, EntityX(n$), EntityY(n$) -0.01, EntityZ(n$))
	EndIf
End Function

End


Ok. I could be blocked by the wall of house this time!! However, my starting position was changed too! Why?
(New position: x= 0, y=6.5, z=2.38.
It should have been: x= 10, y=5.6, z=120
because "PositionEntity camera_pivot,10,5.6,120")

I am using update v.191. Any ideas?

Thanks in advance
Sammy
:)

I haven't looked at the code, but I'm guessing the reason the starting position is off is because of collision detection. Make sure to move to the starting position before calling the collisions command.

Yup, I use set collisons, then create entities, then move them, then set type. Like so..

camera_pivot = CreatePivot()
PositionEntity camera_pivot,10,5.6,120
EntityRadius camera_pivot,1.4
EntityType camera_pivot, PLAYER


Hi jhocking and PCD GUY,

I try to move "Collisions" command to the very beginning of the program and this does not help.

Thanks
Sammy
:)

Hi Sammy.
I've had similar troubles with the tutorial in the last few days, but I've managed to get past this problem...

I've got the collisions commands right before the game loop:
Collisions CARPET,SCENERY,2,1
Collisions PLAYER,PROPS,2,1

While Not KeyHit(1)
...
Wend

I have camera_pivot set up like this:
EntityRadius cameraPivot,1.4
EntityType cameraPivot,player
PositionEntity cameraPivot,0,5.6,120

I have floor1 set up like this:
EntityRadius floor1,.4
EntityTexture floor1,cube_tile
EntityType floor1,CARPET
PositionEntity floor1, 10,6,120
ScaleEntity floor1,8,0.06,13
ScaleTexture cube_tile,.5,.5

The kitchen is setup up like this:
EntityRadius kit, 1.1
EntityTexture kit,kit_tex
PositionEntity kit,10,6.5,128
ScaleEntity kit,0.08,0.08,0.08
EntityType kit,PROPS

And the shop like so:
EntityRadius TTshoppe, 1.1
EntityTexture TTshoppe,TTshoppe_tex
PositionEntity TTshoppe,10,6.5,112
RotateEntity TTshoppe,0,180,0
ScaleEntity TTshoppe,0.08,0.08,0.08
EntityType TTshoppe,PROPS

You'll notice that for the kitchen and shop, I've put EntityType after PositionEntity.
If you put EntityType before PositionEntity, the z coordinate of camera_pivot changes to 2.28102!

This is really strange. If anyone has an explanation for this, I'd be really interested to find out why this happens.

Anyway, put EntityType after PositionEntity, and that'll hopefully take care of the problem.

Hi ervin,

Yes, you are absolutely right!!!
I tried your method and the coordinates are correct.
Also, if we change codes to
....
x# = EntityX(camera_pivot)
y# = EntityY(camera_pivot)
z# = EntityZ(camera_pivot)
terra_y# = TerrainY(terrain,x#,y#,z#)+1.6
PositionEntity camera_pivot,x#,terra_y#,z#
touchGround(floor1)
touchGround(floor2)
touchGround(floor3)
touchGround(floor4)
TurnEntity nacar,0.5,0.5,0
UpdateWorld
RenderWorld
....

we could successfully be blocked by the houses and not go through them!

Moreover, I find that the starting position is also very important.
PositionEntity camera_pivot, x, 6.5, 120

1. If x = 2, the starting coordinates are reasonable. camera_pivot is seperated from shop.3ds or other buildings.
2. If x = 10, the starting coordinates are unreasonable. The reason I think: the camera_pivot ALREADY collided with shop.3ds (with EntityRadius overlap!)and this is also related to EntityRadius of shop.3ds and camera_pivot!
(You could tried other values of EntityPosition of camera_pivot. I think these kind of problems could be avoided if tool like "World Assembler" was used as objects are placed visually.)

In battle004.bb, these 2 problems affect the starting coordinates and collisions again.
1. "Floor1": EntityType should after PositionEntity
2. PositionEntity camera_pivot,x,z,y

Now, I could move on to other tutorials...

Thanks a lot.
Sammy
:)

Glad I could help.

Yes, it seems that if your starting position is inside something you can collide with, it throws your start position off.

Looks like all of you guys are overlooking the ResetEntity command.

Just use it after invoking your movement commands (regardless of whether collisions are turned on or not) and you enitities won't be hampered by (run into) the game objects.