doors

Blitz3D Forums/Blitz3D Beginners Area/doors

chwaga(Posted 2007) [#1]
I'm stuck at the most boring part of a game engine: doors. How exciting!! Anyways:

I need to have a door system (with an infinite amount of possible doors) with which using a function:

Function createdoor(x, y, z, mesh, texture, radius)
;-----???
End Function


these doors are automatic sliding doors with a given radius in XZ distance (I've got an "algorithm" for finding that) where if the player gets close enough in xz, then it slides up (using an updatedoors() function called in every game loop).

I tried using types but got stumped when it comes to making a type into an in-game mesh. It must be a type so that I can use

For door.doors = each door ... Next


Making it possible to run through and update each door, dispite whether there are 2 or 463,345,950 doors.

Thanks for any help you can give!


Yo! Wazzup?(Posted 2007) [#2]
It's a pretty good door thingie, with 4 different kinds of doors.



You either want the movement or movement and rotation?


chwaga(Posted 2007) [#3]
movement, like sliding doors


chwaga(Posted 2007) [#4]
hmm...I may be able to use that...but I think if somebody could just answer how I can use types as meshes, I could make a more efficient one myself.


Jsoren(Posted 2007) [#5]
couldent you just make type 'door' with mesh and x,y,z fields:
type door
 field mesh
 field x,y,z
 field etc
end type

and then just make the doors
Function createdoor(x, y, z, mesh, texture, radius)
 door.door=new door
 door\mesh=copyentity(mesh)
 entitytexture door\mesh,texture
 scaleentity door\mesh,radius,radius,radius ;(if this is   what you mean to use radius for)
 positionentity door\mesh,x,y,z
End Function

you cant make an unlimitid amout, it would just get too slow eventually, but it should work

...or am I just TOTALLY missing your point...


chwaga(Posted 2007) [#6]
OH!!! copyentity! thanks!

EDIT: Also, I meant with the radius, how close in xz distance you have to get, before the door slides up (automatic sliding doors)


Jsoren(Posted 2007) [#7]
glad to help


puki(Posted 2007) [#8]
This appeared recently in the code archives (well, it got bumped) - I've not even looked at it:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1970#comments


chwaga(Posted 2007) [#9]
I'll use Jsoren's method, but in the "Updatedoors()" function, I'll hide any doors that are n far away (or out of view?). That oughta speed it up?


chwaga(Posted 2007) [#10]
OK: I'm having a few bugs, this won't work, I get runtime error: entity does not exhist on the Copyentity line. Here's the code

Function CreateDoor(door_x, door_y, door_z, door_mesh, door_tex)

	door.doors = New doors
	Local d_m  = LoadMesh(door_mesh)
	door\doormesh = CopyEntity(d_m)
	If door_tex <> "" Then 
	Local d_t = LoadTexture(door_tex)
	EntityTexture door\doormesh, d_t
	EndIf 
	door\doorx = door_x
	door\doory = door_y
	door\doorz = door_z
	PositionEntity door\doormesh, door\doorx, door\doory, door\doorz
	
	;FreeTexture d_t
	;FreeEntity d_m


End Function 



Jsoren(Posted 2007) [#11]
ok, has door_mesh been declared as a string?
and is door_mesh a valid path to a mesh when you call the createdoor(x,y,z,mesh,tex) function?
thats all I can think of atm.


chwaga(Posted 2007) [#12]
heh, forgot about the string thing, thanks...


chwaga(Posted 2007) [#13]
ah well, nothing is ever too easy, I've got another bug with the distance in x and z registerring:



when i run it in my program with a door in-game, the text saying what xz distance is will ALWAYS be zero, whether or not the the man is placed at 0, 0, 0 and the door at 10000, 0, 10000. The rest of the code is functioning, if the door goes out of view, it won't draw the text (meaning the in-view thing is working).

Any ideas?


Jsoren(Posted 2007) [#14]
ok, as far as I can tell your problem is here:
distxz# = Sqr(x*x + z*z)

you havent used the 'x' and 'y' variables anywhere else that i can see, so it seems that it should read
distxz# = Sqr(distx*distx + distz*distz)



chwaga(Posted 2007) [#15]
dang!! those typos!! lol I need more sleep, thanks!

by the way, If i'm reading the xz code correctly...is that pythagora's theorum??


Jsoren(Posted 2007) [#16]
lol, I was just about to say, these are exactaly the kinda mistakes I make when Ive been up too long working on something too boring ;P


chwaga(Posted 2007) [#17]
definately the boring-ness, I'm doing my combat engine next ( i hope) though, so uber-exciting! I just noticed, the ^ carrot works in blitz...that saves some time...

It's funny, whenever I post a question here, I check on the thread every 5-10 minutes to see if there's been a response, and whenever I find that somebody has responded, It's usually just happened 10 seconds ago.


chwaga(Posted 2007) [#18]
it works! thanks!


chwaga(Posted 2007) [#19]
OK, small ditto: how do I add sound? Each door must be able to have its own individual sound


Jsoren(Posted 2007) [#20]
do you mean each door needs to have a different sound or all the same?
if their all the same just loadsound() in the beginning of your program and play it everytime you open/close the door, all the commands are in the b3d command ref.


chwaga(Posted 2007) [#21]
hehe, I said "EACH DOOR MUST BE ABLE TO HAVE ITS OWN INDIVIDUAL SOUND" :) which answers your question


Jsoren(Posted 2007) [#22]
yeah but if you have 100-1000+ doors....thats alot of sounds


chwaga(Posted 2007) [#23]
I know...I'll just load a global set of door sounds and call them according to the sound # assigned to each door as a field. thanks!


chwaga(Posted 2007) [#24]
OK!! sound works! It's funny, cause I'm using a dummy mesh of a person as a door ATM, it's hilarious to hear door sounds when watching a person slide up.

However, there is one more small problem that needs fixing. using entityinview and entityvisible don't quite work with what I need. I use if entityinview and visible then do the updatedoors on that door (saving speed and memory). However, many times will a person walk through a door, but be moving fast enough to have the door out of view before it can finish opening and closing, so many times will a door just be hanging there, and when a person looks back at the door, finally, the door closes with the sound... ditto!

What commands/methods could I use to say, If a 3d line is drawn between the camera and the door without colliding into any other objects, then do the doorupdates for that door. If this is possible, it should mainly fix the bug.


Jsoren(Posted 2007) [#25]
well, im not sure why your not using just entitydistance, using entitydistance along with entityvisable and entityinview shoudl be the same as using a 3d line. otherwise you can either use timers, or you can use a true\false value to decide whether the door is finished opening\closing or not.


chwaga(Posted 2007) [#26]
k thanks, I'll use distance with it, forgot about that :)

OK it works, I used :

If EntityInView (door\doormesh, cam) And EntityVisible (door\doormesh, cam) Or distxz (door\doormesh, cam) < door\doorradius*3 Then



in case you're interested