need to open a door

Blitz3D Forums/Blitz3D Beginners Area/need to open a door

Aussie(Posted 2008) [#1]
Hello All.

I have just purchaced blitz 3d & have been playn around with the demo for a while but haven't realy done any programing since the days of the good old C64.

I am trying to make a door slide open & can't quite figure it out. I have managed to make it open although i can't move the camera around when the door opens. I know the reason why it is doing this. Can anyone help me make the door open while i can still move the camera around.

Any help would be appreciated.

here is the code

Graphics3D 800,600,0,1

SetBuffer BackBuffer()


Global door
Global cam_col=1
Global room_col=2
Global door_col=3

Collisions Cam_col,room_col,2,2
Collisions cam_col,door_col,2,2

light=CreateLight()

room=LoadMesh ("cube1.b3d")
PositionEntity room,0,-100,0
EntityType room,room_col

door=LoadMesh ("door.b3d")
PositionEntity door,0,-100,200
ScaleEntity door,1,1,.3
EntityType door,door_col

campivot=CreatePivot()
EntityType campivot,cam_col
EntityRadius campivot,3

camera=CreateCamera(campivot)
PositionEntity camera,0,50,0
EntityType camera,cam_col

While Not KeyDown (1)

TranslateEntity campivot,0,-.5,0

If KeyDown (203)
TurnEntity campivot,0,1,0
ElseIf KeyDown (205)
TurnEntity campivot,0,-1,0
End If
If KeyDown (208)
TurnEntity camera,1,0,0 ElseIf KeyDown (200)
TurnEntity camera,-1,0,0
EndIf
If KeyDown (30)
MoveEntity campivot,0,0,1
ElseIf KeyDown (44)
MoveEntity campivot,0,0,-1
EndIf

If EntityCollided (campivot,door_col)
timer=MilliSecs()
While MilliSecs() <timer+2000
MoveEntity door,0,+1,0
UpdateWorld
RenderWorld 2
Flip
Wend
EndIf

UpdateWorld

RenderWorld
Flip

Wend


Matty(Posted 2008) [#2]
One method, a simple method, is at the end of your little loop for opening the door (after wend), would be to change the entitytype of the door to zero, basically :

EntityType door,0

This would remove it from all collision checking and allow the game to ignore that door from that point on.

One point I notice though is that having a separate while/wend loop within the main while/wend loop just for opening a door is not the way I would have gone about doing this. For example, if you had various particle effects flying about they would suddenly cease updating, unless you call your functions to 'updatestuff' in the other loop as well.


Aussie(Posted 2008) [#3]
Thanks Matty.

Yeah. I knew that the loop inside the main loop is what's causing the problem of not being able to move the camera as the door was opening.

What would be the best way to open the door without having a loop within the main loop?
I am just playing around with things at the moment & at the same time learning how to program.


Matty(Posted 2008) [#4]
Okay, (just taking a brief moment during half-time) -

It all depends on what you are trying to do, in terms of how you go about solving this problem.

I'll give you a way which is similar to how I do it in my current games.

In the example I give I will try to use obviously named variables and will avoid using types/arrays and other code that beginners can struggle with at first (I'm assuming you are a beginner - I apologise if I'm wrong):




;Outside of your main loop, when you load your level, place doors etc you might set a variable like this:

DoorState = 0 ; 0 = closed, 1 = opening, 2 = open, 3 = closing
DoorAngle# = 0.0 ;door swings between an angle of 90 degrees about a pivot point you would place at the door hinge.
DoorTimeToRemainOpen = 3000 ;milliseconds
; then inside your main loop
REPEAT ;game loop



Moveyourcamera, and everything else.....here

SELECT DoorState ;if you have multiple doors you are going to need to store each door's doorstate, and other properties somehow, the easiest way is with TYPEs - when you get used to them,

CASE 0 ;closed

IF 'collided with door' THEN DoorState = 1;your current collision method seems fine so use that...
;okay we've collided with a closed door, so it is time to set it to 'opening'

CASE 1 ;opening
	TURNENTITY DoorEnt,0,1,0
	DoorAngle=ENTITYYAW(DoorEnt)
	IF DoorAngle >= 90 then ROTATEENTITY DoorEnt,0,90,0 :DoorState = 2:ENTITYTYPE DoorEnt,0:DoorClosingTime=Millisecs()+DoorTimetoRemainOpen


CASE 2 ;open
	If Millisecs() > DoorClosingtime then DoorState = 3		

CASE 3 ;closing
	TurnEntity DoorEnt,0,-1,0
	DoorAngle=EntityYaw(DoorEnt)
	If DoorAngle <=0 then RotateEntity DoorEnt,0,0,0:DoorState=0:EntityType DoorEnt,DOORTYPE ;whatever you have set your door collision type number to


END-SELECT


updateworld
renderworld
flip



UNTIL KEYDOWN(1) ;end of game loop






Aussie(Posted 2008) [#5]
Very much a beginner.
Gota start somewhere.

Thanks heaps.

here is what i came up with before. Got the door to open it just wouldn't stop opening.

______________________________________________________

Graphics3D 800,600,0,1

SetBuffer BackBuffer()

Global campivot
Global cam_col=1
Global room_col=2
Global door_col=3
Global door
Global door_open = False
Global door_y

Collisions Cam_col,room_col,2,2
Collisions cam_col,door_col,2,2

light=CreateLight()

room=LoadMesh ("cube1.b3d")
PositionEntity room,0,-100,0
EntityType room,room_col

door=LoadMesh ("door.b3d")
PositionEntity door,0,-100,200
ScaleEntity door,1,1,.3
EntityType door,door_col

campivot=CreatePivot()
EntityType campivot,cam_col
EntityRadius campivot,4

camera=CreateCamera(campivot)
PositionEntity camera,EntityX(campivot),50,EntityZ(campivot)
EntityType camera,cam_col

Function opendoor()
If door_open=False dy=0
If EntityCollided (campivot,door_col) door_open=True
timer=MilliSecs()
dy=1
If door_open=True
MoveEntity door,0,dy,0
If MilliSecs() = Timer +2000 Then door_open = False
EndIf
End Function


While Not KeyDown (1)

TranslateEntity campivot,0,-.5,0

If KeyDown (203)
TurnEntity campivot,0,1,0
ElseIf KeyDown (205)
TurnEntity campivot,0,-1,0
End If
If KeyDown (208)
TurnEntity camera,1,0,0
ElseIf KeyDown (200)
TurnEntity camera,-1,0,0
EndIf
If KeyDown (30)
MoveEntity campivot,0,0,1
ElseIf KeyDown (44)
MoveEntity campivot,0,0,-1
EndIf
opendoor()

UpdateWorld

RenderWorld
Flip

Wend

End
_____________________________________________________

Will go over your code & see how i go, probably tomorow.

Thanks again


Nate the Great(Posted 2008) [#6]
I simply added a variable that told if the door had already been open

also Please use code code or codebox

Graphics3D 800,600,0,1

SetBuffer BackBuffer()

Global campivot
Global cam_col=1
Global room_col=2
Global door_col=3
Global door
Global door_open = False
Global door_y
Global door_opened = False

Collisions Cam_col,room_col,2,2
Collisions cam_col,door_col,2,2

light=CreateLight()

room=LoadMesh ("cube1.b3d")
PositionEntity room,0,-100,0
EntityType room,room_col

door=LoadMesh ("door.b3d")
PositionEntity door,0,-100,200
ScaleEntity door,1,1,.3
EntityType door,door_col

campivot=CreatePivot()
EntityType campivot,cam_col
EntityRadius campivot,4

camera=CreateCamera(campivot)
PositionEntity camera,EntityX(campivot),50,EntityZ(campivot)
EntityType camera,cam_col

Function opendoor()
If door_open=False dy=0
If EntityCollided (campivot,door_col) door_open=True
timer=MilliSecs()
dy=1
If door_open=True And door_opened = False Then
	MoveEntity door,0,dy,0
	If MilliSecs() = Timer +2000 Then
		door_open = False
		door_opened = True
	EndIf
EndIf
End Function 


While Not KeyDown (1)

TranslateEntity campivot,0,-.5,0

If KeyDown (203)
TurnEntity campivot,0,1,0
ElseIf KeyDown (205)
TurnEntity campivot,0,-1,0
End If
If KeyDown (208)
TurnEntity camera,1,0,0 
ElseIf KeyDown (200)
TurnEntity camera,-1,0,0
EndIf
If KeyDown (30)
MoveEntity campivot,0,0,1
ElseIf KeyDown (44)
MoveEntity campivot,0,0,-1
EndIf
opendoor()

UpdateWorld

RenderWorld
Flip

Wend

End




Aussie(Posted 2008) [#7]
Gday & thanks for the help.
I have just tried your code Nate but the door still keeps moving. I found some code in the archives for doors i think i will study them as well & try the way Matty sugested.
All help is much appreiciated. Will use code boxes from now on. I didn't know how to do before.


Nate the Great(Posted 2008) [#8]
sorry I could not test my code because I didn't have time


Aussie(Posted 2008) [#9]
No worries. I apreciate the time taken to help & offer sugestions.


Nate the Great(Posted 2008) [#10]
Hmm It works for me did you set door_opened as a global variable?


Nate the Great(Posted 2008) [#11]
Does this work??




Aussie(Posted 2008) [#12]
Nope door dosn't move. I set door_opened as global but still keps moving. ????


Aussie(Posted 2008) [#13]
Ok i got the door to open using this code


now just got to get it to shut. I will play around with it & see what i can do.


Aussie(Posted 2008) [#14]
don't worrie. I fixed it, it was the () after the millisecs i missed.
Thanks once again for all the help. :)


Nate the Great(Posted 2008) [#15]
You're welcome Good luck :)


Blitzplotter(Posted 2009) [#16]
This is a great start point for a hinged point for a tippable flatbed trailer.