Pivot/model open/close door?

Blitz3D Forums/Blitz3D Programming/Pivot/model open/close door?

Chad(Posted 2007) [#1]
What would you suggest I do for this?

I have modelled a wall with anopen space for a door, and saved that entity. Then I modelled the door as a seperate file. I want to be able to open the door (no key or anything else) when I press "h". Would you suggest that I use a Pivot and parent it to the wall with the door as a child? Or rotate the door to my desired angle when "h" is pressed?

There are no animations, I just want it to spring open, but if there is a no animating way of opening it and have it slowly swing open that would be really good.

If this is possible I'd really like to have this as an option. The longer I press and hold "h" then it the door swings open, is this possible?


b32(Posted 2007) [#2]
You could move the door with PositionMesh to change it's centerpoint. Ie: PositionMesh door, MeshWidth(door) / 2, 0, 0

For the movement, you can use KeyHit() to determine if the key was hit for the first time, after that use KeyDown to determine wheter it's down or not.

I would use a 'flag' variable, say 'doorphase' that is zero at the start of the program.
This variable determines the behaviour of the door.
I would make three states:
1. door opens
2. door shuts
3. door opens completely

These stages can be handled by a Select..Case structure:
Select doorphase

Case 1
..
Case 2
..
Case 3
..

End Select

Instead of checking the position/rotation of the door, I would use a variable to count, like this:
Case 1
 Move door, 0.25, 0, 0
 time = time + 1
 if time = 30 then phase = 3


So, at the start of the program, 'doorphase' is zero.
Only when 'doorphase' is zero, the "H" key can be used.
When the key is hit, doorphase becomes one and the program executes all code that is after 'Case 1' in the Select part.
The door moves open. If the key isn't down anymore, it should shut again. (phase=2)
If the door is beyond a certain point (ie. time > 30), the door is 'unstoppable' and moves open completely. (until time = 50)
After that, doorphase should be four, preventing the door from being opened (any further).


Chad(Posted 2007) [#3]
Thanks for the quick reply, I'll give it a go and report back if I have problems. Thanks!


Chad(Posted 2007) [#4]
Ok, I've ran into a problem with the select, as of right now I was just toying around and just trying to get select working and I can't get the entityalpha to work with the select I'm using now.. Take a look please and could you tell me what I'm doing wrong?

Global which_one=0
Global hatchclosed
Global hatchopen

which_one=0
hatchclosed=LoadMesh("hatch.b3d")
PositionEntity hatchclosed,0,15,-.9
ScaleEntity hatchclosed,.25,.25,.25
EntityType hatchclosed,LEVEL_COL

hatchopen=LoadMesh("hatch.b3d")
PositionEntity hatchopen,-1.8,15,-1.8
RotateEntity hatchopen,90,0,90
ScaleEntity hatchopen,.25,.25,.25
EntityType hatchopen,LEVEL_COL

EntityAlpha hatchclosed,1
EntityAlpha hatchopen,0

While Not KeyHit(1) 

If KeyHit(35) Then
	which_one=which_one+1
	Select (which_one Mod 2)
		Case 0
			EntityAlpha hatchclosed,1
			EntityAlpha hatchopen,0
		Case 1
			EntityAlpha hatchopen,1
			EntityAlpha hatchclosed,0
	End Select
	EndIf


This is just pertaining to the entitties and select, it runs, but both cases load and both are visible instead of one being invisible.


b32(Posted 2007) [#5]
Maybe it is something else? Since I tried this:

and it seems to work okay.


D4NM4N(Posted 2007) [#6]
simply model it and export from the modeller with the pivot(axis) where you want it to rotate (ie at the edge). Or if not doing modelling, do a createcube and positionmesh the verts by half the meshsize (or fitmesh prob better) as suggested above.

Then just create a 4 state latch and trigger but using turnentity: (im using custom types here (d\) but you could use arrays or just a variable if you have only one door).

**edit, added a working vrsion to codearcs
http://www.blitzbasic.com/codearcs/codearcs.php?code=1970


You could improve the above with an incremental doorspeed to get a slamming effect, but remember to reset the angle once it has passed the stops ie:

if entityyaw(d\door) <0 then rotateentity d\door,0,0,0