rendering new environments

Blitz3D Forums/Blitz3D Beginners Area/rendering new environments

airborne(Posted 2012) [#1]
Would anyone be able to give me an example of a code to transition from one location to another on keypress? I have the main world and buildings of my game rendered via sketchup and i have it functioning in blitz fine, I'm just attempting figure out how to walk up to a door, press a button and go into that room/building (obviously would have to create the room in sketchup as well) I'm just a little stumped on how the code would work. Any advice appreciated thanks :)


airborne(Posted 2012) [#2]
bump


Yasha(Posted 2012) [#3]
...I think this topic is way too big to give any meaningful help without knowing something about the way your game is already set up. There are as many ways to handle levels and environments are there are to make a game, not least because the concept of "room", "level", "environment" etc. is itself really too vague to be useful by itself.


Zethrax(Posted 2012) [#4]
I'd suggest you take a browse through the 3D samples that came with your Blitz3D download. You'll get a clearer idea of what's involved after looking at the sample code and seeing it in action.


Ferret(Posted 2012) [#5]
Not that hard to do.
If Keyhit(key) Then PositionEntity(entity,x,y,z)


Look at picking commands and make the door pickable.
EntityPickMode(door,2)
If CameraPick(camera,x,y) = door Then PositionEntity(entity,x,y,z)



Mikorians(Posted 2012) [#6]
Load next map? Simple question people...

You will need to detect the portal location somehow by detecting if you're near something with either:

1. An array of coordinates stored in a file compared against the player/camera's location with the common distance formula:
Where (X1,Y1,Z1)=Source (X2,Y2,Z2)=Target
Dist = Sqr((Abs(X1 - X2) ^ 2) + (Abs(Y1 - Y2) ^ 2))
Dist = Sqr((Dist ^ 2) + (Abs(Z1 - Z2) ^ 2))

2. Using the collision detection functions (no keypress required)

Then either:

1. Dump the old map data out with the various FreeEntity functions, and load the new map and model information into your program.

2. Assuming you've compiled your program into executable form,
using the Fastextensions (a separate library you can purchase)
ExecAndExit function to call your next .exe program (I haven't tried the built in ExecFile or End commands yet so try them out)


RemiD(Posted 2012) [#7]
Assuming you want to use a loading screen or a screen with an animation of a door (as in Morrowind or Resident Evil) when the player activates a door. (not a streaming engine)

This is how i would do it :

Step 1 : detect if the player activates the door :
you can check if a collision happened between the player collider and the door collider
or
you can check if a door collider has been picked after a linepick (after a KeyHit() for example)

Step 2 : do the transition between the outdoor to the indoor or to a zone to another zone :
Disactivate the player controls
and
you can show a loading screen with an image displayed (it can be the name of the zone or a screensot of the zone)
or
you can show an animation of a door being opened

During this step,
you can delete all entities of the previous zone and load all entities of the next zone (the list of entities to load depending on the zone can be directly in the bb code or written in an external file)
or
you can simply use HideEntity(PivotZone001) and ShowEntity(PivotZone002) where PivotZone001 and PivotZone002 are pivots which are parents of some entities depending on their zone. In this case, there is no need to delete or to create anything because all entities have been previously loaded/created and set as childs of a pivot depending on their zone.

Step 3 : show the new zone, return to the game
you can now show the new zone
and
position player to the wanted position (the other side of the door)
and
reactivate the player controls

Last edited 2012

Last edited 2012


airborne(Posted 2012) [#8]
yeah mostly like the elderscroll series, mostly noticable in skyrim how the door would open slightly then load into the room, i did do a ton of digging into code example/posting archives. I appreciate all the info everyone it'll at least give me something to experiment with. This is what I'm working with now, keep in mind it's a test program for this purpose, no game entities or textures are in this code line, so you very well could run this yourself. The biggest problem with this code right now, is that "entityradius" command is forcing the sphere object down into the plane, as soon as the sphere collides with either cube it sticks, it is intended to "positionentity" from one sphere to the other upon contact. In anycase, code example is in next post.


airborne(Posted 2012) [#9]
;opening settings
Graphics3D 1240,800,16,2
SetBuffer BackBuffer()

;camera and light settings
light=CreateLight()
camera=CreateCamera()
CameraRange camera,1,10000
CameraClsColor camera,0,0,255
AmbientLight 50,50,50
RotateEntity light,90,0,0

;Misc. Object transparency/gravity/collision
alpha#=1
type_plane=1
type_player=2
type_scenery=3

;create plane
;ground
plane=CreatePlane()
PositionEntity plane,0,-1,0
EntityColor plane,0,255,0
EntityType plane,type_scenery
EntityRadius plane,2
EntityBox plane,-2,-2,-2,4,4,4

;player object
sphere=CreateSphere()
ScaleEntity sphere,0.1,0.1,0.1
EntityColor sphere,255,0,0
PositionEntity sphere,30,0,0
PositionEntity camera,30,0,0
ScaleEntity sphere,0.1,0.1,0.1
EntityParent camera,sphere
EntityType sphere,type_player
EntityType camera,Type_player

;building objects
cube=CreateCube()
PositionEntity cube,-25,0,0
EntityType cube,type_scenery
EntityColor cube,255,0,0
cube1=CreateCube()
PositionEntity cube1,25,0,0
EntityType cube1,Type_scenery
EntityColor cube1,0,0,255
x#=0
y#=0
z#=0
EntityRadius sphere,sphere_radius#
EntityRadius cube,cube_radius#
EntityRadius cube1,cube1_radius#

;Player Object Keyboard and Mouse Controls
While Not KeyDown(1)
If KeyDown(32)=True Then TurnEntity sphere,0,-1,0
If KeyDown(30)=True Then TurnEntity sphere,0,1,0
If KeyDown(31)=True Then MoveEntity sphere,0,0,-0.05
If KeyDown(17)=True Then MoveEntity sphere,0,0,0.05
If KeyDown(207)=True Then MoveEntity camera,0,0,1
If KeyDown(199)=True Then MoveEntity camera,0,0,-1
If KeyHit(57)=True Then MoveEntity sphere,0,10,0
mxs# = mxs# + MouseXSpeed()
mys# = mys# + MouseYSpeed()

If msx# > 45 Then mxs# = 0
If msx# < 0 Then Msx# = 45

If Mys# > 45 Then mys# = 45
If mys# < -45 Then mys# = -45

RotateEntity camera,mys#,-mxs,0
MoveMouse 620,400
If MouseDown(3) Then MoveEntity sphere,0,0,0.5

;Set Collision Method and Response Values
method=2
response=2

method_info$="ellipsoid-to-polygon"
response_info$="slide1"

MoveEntity sphere,0,-0.50,0 ;Gravity


;Change Collision Method
If KeyHit(1)=True
method=method+1
If method=4 Then method=1
If method=1 Then method_info$="ellipsoid-to-sphere"
If method=2 Then method_info$="ellipsoid-to-polygon"
If method=3 Then method_info$="ellipsoid-to-box"
EndIf

;Change Collision Response
If KeyHit(1)=True
response=response+1
If response=4 Then response=1
If response=1 Then response_info$="stop"
If response=2 Then response_info$="slide1"
If response=3 Then response_info$="slide2"
EndIf
;Enable collisions between type_character and type_ground
Collisions type_player,type_player,2,2


;Enable collisions between type_character and type_scenery
Collisions type_player,type_scenery,method,response

;Enable collisions between world/buildings/player
For k = 1 To CountCollisions(sphere)

If CollisionEntity(sphere,k) = cube Then
PositionEntity sphere,26,0,0
EndIf

If CollisionEntity(sphere,k) = cube1 Then
PositionEntity sphere,-26,0,0
EndIf
Next

Flip
UpdateWorld
RenderWorld
Text 10,10, "x: " + EntityX(sphere) +" y: " + EntityY(sphere) + " z: " + EntityZ(sphere)
Wend
End


airborne(Posted 2012) [#10]
Nearly forgot, -home- and -end- key function camera zoom in/zoom out.


airborne(Posted 2012) [#11]
so, i can seem to move objects on contact now, but it would seem that walls tend to block character entity from being placed in the room


RemiD(Posted 2012) [#12]
Airborne>>From my tests, if you want to move a collider through others colliders (in this case in order to position the Player at the other side of the door), you have to delete the collider, then position the Player, then create a new collider.

You can read on others posts on this forum that it is possible to use either :
HideEntity(Collider)
ShowEnitty(Collider)
or
ResetEntity(Collider)
in order to achieve the same effect (move a collider through others colliders)
however i have not found it works properly or maybe i have not used it in the correct way.
See this example :
http://blitzbasic.com/Community/posts.php?topic=98459#1150341


Ferret(Posted 2012) [#13]
I don't understand why a mesh has to pass trough another mesh when repositioning.
It just needs to be drawn at the specified location, not moved.


airborne(Posted 2012) [#14]
What I ended up doing was... leaving a ceiling off a room, and moving said object above the room, when it loads the character falls into the room, the interesting thing about this is, you never even notice the player object falling, it just shows the room upon loading.... Well guys onto other things now days... new maps... trying to animate so on and so forth... good luck with your projects.


airborne(Posted 2012) [#15]
nearly forgot... an easy fix to this problem also involves making the ceiling a non-collidable object, so the character would simply pass through it, as long as the character cant jump into it/touch it, then a player would simply never know.
-Remi, thanks for the advice, I'm still learning Blitz so what you have been saying more or less i've been attempting to understand, but with all the work i've put into collisions thus far i think i get what you're saying now, simply integrate hide/show into the function lines when moving between rooms, even though it does feel like a tricky thing to balance, you have my gratitude as attempting to create a separate object for a ceiling and then properly position it so that it blocks character view from the outside would be pain-staking.

Last edited 2012


K(Posted 2012) [#16]
Use this instead of PositionEntity:
Function Repos(entity,x,y,z,Yaw=-500)
 t=GetEntityType(entity)
  EntityType entity,0
   PositionEntity entity,x,y,z,1
  If Yaw<>-500RotateEntity entity,EntityPitch(entity,1),Yaw,EntityRoll(entity,1),1
 EntityType entity,t
End Function

..and all issues go away.

Last edited 2012


RemiD(Posted 2012) [#17]
K>>I have tried to delete the EntityType in order to be able to reposition the entity but it does not always work, see the example in the link i have posted above.



i think i get what you're saying now, simply integrate hide/show into the function lines when moving between rooms, even though it does feel like a tricky thing to balance


Airbone>>
No i don't suggest you use EntityType(Collider,0) or HideEntity(Collider) then ShowEntity(Collider) because from my tests it does not work in all cases.
What i suggest is to set the mesh as a child of the collider and when you want to reposition the mesh, you unset the parent>child relation with the collider, you delete the collider, you create a new collider at the position you want, and you set the mesh as a child of the new collider. From my tests, this will work correctly in all cases.

For example :


If you create a routine that manages the creation/deletion of all moving sphere colliders in this way, this is easy to do.

Last edited 2012


airborne(Posted 2012) [#18]
XD kindof on the back burner for right now, I don't know what the hell happened but I cant even get the open world to free, and individual rooms to load in place of the open world... ugh, this is taxing