Door Open
Blitz3D Forums/Blitz3D Beginners Area/Door Open
| ||
I am trying to create a opening door. I searched for "door" and "door open" in the forums but found nada so I post here. My idea is to create an animated door in milkshape or something similar and the when event is triggered to open the door. My question is: Should this be a .b3d or a .x filetype? |
| ||
Couldn't you use TurnEntity? |
| ||
Hey Rook, try this out. Use the spacebar to open and shut the door. I've commented it, so hopefully it will be of some use to you :)Global wall_left=CreateCube() ScaleEntity wall_left,4,4,0.1 PositionEntity wall_left,-6,0,0 Global wall_right=CreateCube() ScaleEntity wall_right,4,4,0.1 PositionEntity wall_right,6,0,0 Global roof_bar=CreateCube() ScaleEntity roof_bar,2,1,0.1 PositionEntity roof_bar,0,3,0 Global hinge=CreatePivot() PositionEntity hinge,-2,0,0 Global door=CreateCube(hinge) ScaleEntity door,2,3,0.2 PositionEntity door,2,-1,0 EntityColor door,128,0,0 Global door_handle=CreateSphere(8,hinge) PositionEntity door_handle,3.5,-1,-0.3 ScaleEntity door_handle,0.2,0.2,0.2 ;********* end of create scene ************ Global door_open=0; 0 = door not moving, 1 = door is shutting, 2 = door is opening Global door_status=0 While Not KeyHit(1) If KeyHit(57) Then; if the space bar pressed If door_status=0 Then; if the door is SHUT then door_open=1; set the door is opening ElseIf door_status=1 Then; if the door is OPEN then door_open=2; set the door to shuting End If End If If door_open=1 Then; if the door is opening open_door(); open it ElseIf door_open=2 Then; if the door is shutting close_door(); shut it End If UpdateWorld RenderWorld Flip Wend End Function open_door() RotateEntity hinge,EntityPitch(hinge),EntityYaw(hinge)+0.4,EntityRoll(hinge); increase the hinge rotation If EntityYaw(hinge)>93 Then; if the door angle is greater than 93, then the door is open door_status=1; set door status to 1 (open) door_open=0; set door to NOT moving End If End Function Function close_door() RotateEntity hinge,EntityPitch(hinge),EntityYaw(hinge)-0.4,EntityRoll(hinge); decrease the hinge rotation If EntityYaw(hinge)=<0 Then; if door angle is 0 or less, then the door is shut door_status=0; set door status to 0 (shut) door_open=0; set door to NOT moving End If End Function |
| ||
I dont see what difference the mesh type needs to be - after all, its only a door! Though I guess if you wanted to animate it to Open/Shut rather than, as electronin says, just turn it, then maybe there is a difference. :) |
| ||
I'd do the opening and shutting in the code, not with an animation. You get more control over it that way :) |
| ||
probably save on vidmem too |
| ||
I'm starting to use blitz primatives more and more :) Mainly because i'm lazy ;) |
| ||
I did a door system, but mine are sliding doors - I modified the 'Dungeon Trigger code' - I mention it, incase a sliding door is required - mine slide left/right, but they could slide/up down. I'm to lazy to make them open like real doors - good stuff "Rossy". |
| ||
Sliding doors are probably less hassle. With normal doors, you have the issue of them opening onto you, and you getting trapped with collisions. :) |
| ||
Cool, RossC! you should put that in the code archives. |
| ||
That works!!! That is great. reTweaking code as I sit here instead of washing the dishes... Wife not happy... Thank Y'all! |
| ||
puki I searched for "dungeon trigger" and found no reference on the site... I want a few sliders too so where could I find that? : ) going to wash the dishes now... |
| ||
Dungeon trigger was a demo of opening a dungeon door - it was made by "Reda Borchardt" I think he was known as "OpenDNA". The demo is located in the Blitz 3D samples directory in the Blitz3D samples folder - However, I am not sure if it is now distributed with Blitz3D - I'm at a loss as to what demos actually are. |
| ||
Ah i remember that demo. I can mail it to you, if you want. |
| ||
Ah i remember that demo. I can mail it to you, if you want. Would you be willing to email it to me, too, please kind sir?bricemanuel at verizon.net |
| ||
ok, np :) |
| ||
Mine is : ralph at silverimports.com |
| ||
I'm starting to use blitz primatives more and more :) Mainly because i'm lazy ;) You'll end up with something like my 'creations' haha "Blockman and the attack of the alien, mutant, marshmallow cone fiends" |
| ||
lol @ Malice :) |
| ||
I'm New To blitz3d but having a good time. I'm having trouble figureing out how To raise a door slowly up( Or down For that matter. the code I use works but too fast. I have looked And can't find any examples. I tryed finding the dundeon thing that Rook mentioned but isn't out there. I appreciacte any help you could give. heres what I've got ;sliding door Graphics3D 800, 600, 0, 1 ;3D graphics at a resolution of 800x600 SetBuffer BackBuffer() ;do all drawing to the back drawing buffer Timer# = MilliSecs(); + 10000 Const PLAYER_COL= 1 Const LEVEL_COL = 2 Const ENEMY_COL = 3 Const BULLET_COL= 4 Global level2 ; Global previous_millisecs_time = MilliSecs() ; Type bullettype ;set up the bullet type Field entityhandle ;create a field to contain the handle of the bullets mesh End Type Type badguytype ;set up the badguy type Field entityhandle ;will contain the handle of the badguys mesh Field state ;will contain the state that the badguy is currently in End Type Type doortype Field entityhandle Field state End Type light = CreateLight() ;Create a light to see RotateEntity light, 30, 30, 0 ;angle the light player = CreatePivot() ;A simple pivot is all we need to represent the player camera = CreateCamera(player) ;create the camera and attach it to the player CameraRange camera, .01, 250 ;set the camera range to something reasonable ;CREATE SKY sky = CreateSphere(40) FlipMesh sky ScaleEntity sky,1000,1000,1000 PositionEntity sky,0,0,0 sky_tex = LoadTexture ("sky.jpg") EntityTexture sky,sky_tex EntityFX sky,1 level = LoadMesh("anewroom&door.b3d") ;load in the level mesh level2 = LoadMesh("door.b3d") PositionEntity level2,0,0,1 FlipMesh level2 EntityType level2,1 EntityRadius level2,1.05 ;============== ; Load gun target ;============== targ=LoadSprite("target.png",1,camera) MoveEntity targ,0,0,50 EntityOrder targ,-2 ;hand held gun Number 2 gun2 = LoadMesh("pistol.3ds") gun2_tex = LoadTexture("pistol.jpg") EntityShininess gun2,0.8 EntityRadius gun2, .5 EntityParent gun2,camera ScaleEntity gun2,.2,.2,.2 PositionEntity gun2,EntityX(camera),EntityY(camera)-1.5,EntityZ(camera)+2 RotateEntity gun2 ,-5,-2,0 EntityOrder gun2,-2 ;HideEntity gun2 bulletmesh = LoadMesh("bullet.b3d") ;load in a bullet mesh (this will be a template mesh) bulletmesh = CreateCone():RotateMesh bulletmesh,90,0,0:ScaleEntity bulletmesh,.1,.1,.1 EntityType bulletmesh, BULLET_COL ;set up collision type for the bullet EntityRadius bulletmesh, .01 ;set up collision radius for the bullet ;HideEntity bulletmesh ;hide the template meshes since they are not actual objects EntityType player, PLAYER_COL ;set up collision type for the player EntityRadius player, .3;, .95,.125 ;set up the players collision radius (1.9 meters tall, .6 meters wide) EntityType level, LEVEL_COL ;set up collision type for the level EntityType level2,LEVEL_COL Collisions PLAYER_COL, LEVEL_COL, 2, 2 ;player to level MoveEntity camera, 0, .9, 0 ;move camera up to height of players head (also moves weapon) MoveEntity player, 0,1,-4 ;move the player to the starting position MoveEntity gun2, .1,-.15,.1 Global previous_millisecs_time = MilliSecs() While Not KeyHit(1) ;ESC key wkey = KeyDown(17) ;collect user input skey = KeyDown(31) ;It's a good practice to collect these inputs only once akey = KeyDown(30) ;per loop. This will prevent odd behaviors from happening, dkey = KeyDown(32) ;for instance if the state of a key changes between multiple mouse1 = MouseHit(1) ;checks of that key while still in the same loop. spacekey = KeyHit(57) If wkey Then MoveEntity player, 0, 0, .1 ;Forward - w key If skey Then MoveEntity player, 0, 0, -.1 ;Back - s key If akey Then MoveEntity player, -.1, 0, 0 ;Left - a key If dkey Then MoveEntity player, .1, 0, 0 ;Right - d key If spacekey Then MoveEntity player, 0,2.5,0 If KeyHit(18) doorup() TurnEntity player, 0, -MouseXSpeed()/5.0, 0 ;rotate player Pivot according to mouse X movement TurnEntity camera, MouseYSpeed()/5.0, 0, 0 ;rotate camera up/down according to mouse Y movement If EntityPitch(camera) < -45 ;don't allow camera to look below -45 degrees RotateEntity camera, -45, EntityYaw(camera), EntityRoll(camera) EndIf If EntityPitch(camera) > 45 ;don't allow camera to look above 45 degrees RotateEntity camera, 45, EntityYaw(camera), EntityRoll(camera) EndIf MoveMouse GraphicsWidth()/2, GraphicsHeight()/2 ;reset mouse position to middle of screen TranslateEntity player, 0, -.1, 0 ;simple gravity UpdateWorld ;figures out collisions If mouse1 ;check if left mouse button was pressed bullet.bullettype = New bullettype ;create a bullet bullet\entityhandle = CopyEntity(bulletmesh) ;create the bullet mesh PositionEntity bullet\entityhandle, EntityX(gun2, 1), EntityY(gun2, 1), EntityZ(gun2, 1) ;place the bullet at the guns position RotateEntity bullet\entityhandle, EntityPitch(gun2, 1), EntityYaw(gun2, 1), EntityRoll(gun2, 1);orientate the bullet with the gun ResetEntity bullet\entityhandle ;otherwise bullet could hit enemy while moving from 0,0,0 to current position EndIf For thisbullet.bullettype = Each bullettype ;iterate through all of the bullets MoveEntity thisbullet\entityhandle, 0, 0, 2 ;move the bullet forward along the bullets Z axis If Abs(EntityX(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds FreeEntity thisbullet\entityhandle ;delete the bullet mesh Delete thisbullet ;delete the bullet ElseIf Abs(EntityY(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds FreeEntity thisbullet\entityhandle ;delete the bullet mesh Delete thisbullet ;delete the bullet ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds FreeEntity thisbullet\entityhandle ;delete the bullet mesh Delete thisbullet ;delete the bullet EndIf Next UpdateWorld ;figures out collisions RenderWorld ;draws the 3d scene Flip ;displays the scene to the screen Wend ;loop until the ESC key is pressed End Function doorup() maxlift = 3.5 For lift# = lift + .001 To maxlift MoveEntity level2,0,lift#,0 currtime_in_millisecs = MilliSecs() time_passed = currtime_in_millisecs - previous_millisecs_time If time_passed > 100 Then time_passed = 100 If time_passed = 100 Then MoveEntity level2, 0,.1,0 ; EndIf Next |
| ||
I think it is the function doorup() that is not in order. It is difficult to try this program without any media (models, textures etc.), but in the doorup() function, I wouldn't expect a FOR..NEXT. The trouble here is, that the function only runs once. It opens the entire door at once, without redrawing the game. Either use RenderWorld() and Flip() in the function (not recommended, because the rest of the game stops) or figure out how to use flags: Say, when a key is pressed, (keyhit(something)), a "flag" is set. A flag is a global variable that can be for instance 1 or 0. When the flag is 1, the door moves up, when the flag is zero, the door stands still. The flag-checking and door-moving should take place in the main loop. "if flag = 1 then move door" This would be the way to get it working: (1) program starts, flag = zero, door doesn't move (2) key is pressed, flag becomes one, makes the door move (3) door hits end position, flag resets to zero again. By expanding/adjusting this method, you can make the door open up while the game keeps on running. |
| ||
one thing you might want to try is using a .3ds animated entity. the door animations will load nicely and you can cycle through all of the partsto make them pickable/collide. it works well. |
| ||
Thanks guys, I know from some of the other discussion about using a animation and I will try that once I get a little more on the anima8or. But I was trying to get the door to open just using the code right now. Don't get me wrong the door opens, but very quick. It is a stone door.it should grind up slowly. I think I understand what your saying about the flags. i think tho' what i am not understanding is how to control the speed at which it goes up. Im thinking it may have something to do with velocity or am I just making this more complcated than it need be. Ill try wat yall have suggested and see what goes. Thanks |
| ||
Ah, I see. Nvm then, I think for choosing the right speed, calculate a global variable "elapsed"newtime = MilliSecs() elapsed = newtime - oldtime oldtime = newtime Then, use "elapsed" for all movement in the program. ie: MoveEntity door, 0, 0, elapsed*0.01 Another way is using tweening. The castle demo in the samples folder uses this. And on this forum, there is a few examples that use CreateTimer. |
| ||
Well I finnally got it to work. I found a really interesting moving platform program by ; ID: 470 ; Author: bradford6 ; Date: 2002-10-25 02:33:08 ; Title: Moving Platforms demo ; Description: collisions with moving platforms I really cut every thing out I didn't need until I had my door going up slow and stopping, but can't yet control when it starts. anyway its cool to watch. Today tho' I dumped that for now and finally got Bram32s' idea to work. I don't know if I did it right, but it does work . Press the "E" key and the door goes up slow only so far and then stops. Right now it only goes up. ; Door_opens.bb ; Well its actually a cube lifting up. I didn't know how to provide the media from my juryrigged code, So I borrowed from my 3D Programming for Teens book ;and cobbled this together. ;_______________ Graphics3D 640,480 SetBuffer BackBuffer() ; Create camera camera=CreateCamera() PositionEntity camera,0,1,0 ; Creating a light light=CreateLight() Global doorflag = 0 ; Creating the terrain ground=CreateTerrain(512) PositionEntity ground, -500,0,-500 EntityColor ground, 0, 235 ,50 door = CreateCube() PositionEntity door,0,1,10 EntityColor door,200,0,10 ; This following code makes our program run While Not KeyDown( 1 ) If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05 If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05 If KeyHit(18) = True Then doorflag = 1 If doorflag = 1 MoveEntity door , 0,.01,0 If EntityY(door) >= 3.5 Then doorflag =0: PositionEntity door,0,3.5,10 RenderWorld Flip Wend End If you can think of any improvments let me know. Thanks for the help |
| ||
Here is a demo of doors ripped out of my long lost FPS engine. It originally handled everything that needed to move at the click of a button e.g. teleports/pits/bridges/walls/columns...pretty much anything that has a trigger and then has to move or hide/show but I have simplified it and commented it to just show doors. There are 4 different doors to see, just uncomment each line in turn ;Movement Create_Door(1,0,0,0,-5,0,0,0,0,0,0,0,0,1,1,0,0.01,sClosedOpenNext) ;Rotation ;Create_Door(1,0,0,0,0,0,0,0,0,0,0,90,0,1,1,0,0.01,sClosedOpenNext) ;Movement and Rotation ;Create_Door(1,0,0,0,0,5,0,0,0,0,90,0,0,1,1,0,0.01,sClosedOpenNext) ;Alpha ;Create_Door(1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0.01,sClosedOpenNext) |
| ||
Thanks alot Shambler . Been real busy this week and haven't had a chance to fiddle with any code . I did run it tho and its doing what I was trying to do alot better than mine did, more flexable. When I was working on the org. code I was trying to figure out how to set a stop variable. You answered that for me. Sometimes I don't know the right questions to ask and its can be frustrating. I have to remember I have to tell it how to do everything. thanks again. |
| ||
I wish you had released something playable with the SARE engine. Why are there so few fps things? Maybe some people around here have made bril stuff, but never showcased it for some reason. |
| ||
I think that an FPS is such an enormous task that's why so many fail to come to fruition...most people don't have your level of determination =) I was thinking of having another bash at it...the core is mostly there but creating the media is something that I have the most problems with and I'm sure the same goes for many programmers. I also tend to lose interest once specific problems are solved, I am a problem solver at heart ( and work ) and tend to move on to other 'conundrums'. If I remember right the PlayerMove() function in SARE was 5 pages long and coped with standing on moving objects/ducking/jumping/sliding off too steep surfaces/smooth movement up/down stairs/ladders and interacting with the enviroment...its things like that I like programming most of all. |
| ||
@Shambler, great door code, easy to read and well structured - cheers! I'm not going for a door as such, more a hinged skinny bit of stuff on the back of a flatbed to tip ducks off, sounds mad, but true (;-) I especially like the comment out the various data set ups you have for different door types. Hope you don't mind a re-post of your code which has been slightly modified, I intend to parent your door slider to the back of an articulated truck's flatbed trailer to let the animals (well, rubber ducks - possibly on wheels!) contained within run/roll free, but I need sleep now.... |