Game Development Community

Dynamically Placing .DIF objects relative to each other

by Jesse Fox · in Torque Game Engine · 05/11/2006 (6:45 pm) · 15 replies

I am new to torque but not programming or C. I would like ideas/suggestions on how to approach this problem from those of you more experienced with Torque.

Goal: I would like to load and place .DIF objects relative to each other so they line up portal to portal.

Problem: I would like to have a way to do this so that the .DIF objects do not have to be all the same size(tiled). Basically I would like a way to line up or 'mount' (i know you can't 'mount' dif files) 2 .dif objects together to make it seemless.

basically 2 dungeon like interiors I have i want to be able to dynamically place them so they line up and appear to the player to be 1.

I have no problem altering the engine in C for this. My first thought is that I am going to have to in some way make an alternative interior instance for this. As I said just looking for ideas or suggestions. Maybe there is an easier solution to this than i suspect. Any suggestions are appreciated.

-Jes

#1
07/03/2006 (5:50 pm)
Posting: Unread posting for more than 30 days. I am posting to help get a reply to your un-answered question.
#2
07/04/2006 (8:48 pm)
I had considered this myself some time back.. The first solution that came to mind was to line up the pieces by hand and get the offset for each piece "x" as it relates to piece "y". Then in script or code it would be easy to plug in the offsets and dynamically place the interiors.
#3
07/04/2006 (11:51 pm)
If you choose your bounding box correctly, you could also use that data for how to offset it.
#4
07/05/2006 (5:13 am)
I'm pretty sure for .dif and .dts placement TGE dynamically creates a bounding box that encloses the entire object and then calculates the center from that shape and uses the center for positioning. I could be wrong, but I do remember playing with the code that generated those bounding boxes and their centers at runtime.
#5
07/05/2006 (12:26 pm)
I'm sorry, I meant if your program is placing the objects, then it can check the objects embedded bounding box and know that "the bounding box ends at 3 in x, so my next object should begin there if I'm placing it along the X axis".

Maybe I'm misunderstanding the question, though. What I was imagining was coridoor pieces, say, that are placed next to each other to produce the final product.
#6
07/05/2006 (12:41 pm)
This has been an ongoing challenge for me, since the mission files I'm creating have a circular layout; not only do I have to futz with the positioning, I have to worry about getting the correct angle of rotation too. Bleah!

As far as positioning goes, the position of your DIF in your creation tool is carried over into the Torque editor. So, if your DIF is offset from the origin by 128 units, when you import it into Torque and set its coordinates to 0 0 0, it will be off-center by 128 units. (Overlooking the difference in scale between Torque and whatever design tool you're using, of course.)

So, if you break your DIFs into modular pieces, and keep their location relative to the origin consistent, you can just import them into Torque and set their location to 0 0 0 and they'll line up beautifully.

I like to create a master template like this:
www.distantfate.net/screenshots/alignment1.jpg
For each module, I start with a copy of the master template, and delete the components I'm not working on. (So, if you're working on Module #3, delete modules 1, 2, 4 and 5.) Keep the offset where it is, and your pieces fit together perfectly when you import them into Torque.

One gotcha to watch out for: if you have to rotate your modules at all, using the axis handles on the object rotates around the center of the object, not its origin. Type in your rotations in the editor, though, and it will rotate around the origin.

Good luck!
#7
07/05/2006 (12:42 pm)
I see what you are saying.. It would be nice to add a utility to the world editor that would alow you to select one object, then click another, and it just output the offset for you automatically. Then you could script the offset into whatever you wanted.
#8
07/05/2006 (12:50 pm)
Oh, I should point out that the modules don't have to be square. As long as your offsets are consistent, they'll line up just fine.

www.distantfate.net/screenshots/alignment2.jpg
#9
07/05/2006 (1:21 pm)
I like Map Section 5. ;-)
#10
07/05/2006 (1:23 pm)
I have an idea... what if you were to just set up an array of attributes in torquescript that contain the offsets, and then your code could just look it up there. This would be a cheap solution in terms of both effort and processor time.
#11
07/06/2006 (4:40 am)
Sorry for the delay in getting back here....

John, not sure I fully understand you. If you have a proper offset from 0,0,0 then that is good for only 1 entrance/exit, no? Knowing where to line up the next map section relative to the second entrance/exit still is a problem... Unless I am not following correctly...

I came up with 2 solutions and encountered a new problem.

solution 1) as Cliff and Brandon said, drop the pieces in the editor and manually check the offset, and plug the offset of each entrance/exit into variables. This works very nice except you must keep everything in set angles. whether it is 90 or 45 degree, everything must be set to a standard angle... It makes the layout very boxy....

solution 2) after you create your .dif you draw out a .dts that is a simple box that is an outline of your whole .dif. On this .dts you mark your exit points, and then drop a node there. Simply use mount nodes and then when you are placing your dungeon, just create a daisy chain of mounted .dts shapes, then when it is set up as you want it, loop through the objects and place a .dif in the same location. You just gotta remember to keep your hotspot/offset/center located in the same spot relatively on the .dif & .dts.... The drawback to this method is you always enter a dungeon piece from the same direction. That is very minor, however considering that you can use any angle connection, and can change elevation without problems...

Of course both methods have the drawback of having to use the same size portal/connection points.

Now the problem I ran in to. Getting some of these .dif pieces from my artists! I even posted in the jobs section to hire an artist for my project, paying money out of my own pocket to fund the project but I haven't gotten any shapes from any of my artists, and have been working on other sections of the game mechanics, but really need to get this going first.

Anyway, I have code written for my solutions #1 and #2, however have not the pieces I can test with. So in essence it is all theory still. I am sure I will run into some unforseen problem, but that is the fun of programming!

-Jes
#12
07/06/2006 (7:59 am)
It's stories like yours, Jesse, that make me glad I'm a coder, artist AND musician. Now if only I had unlimited time to go with it. heh.
#13
07/06/2006 (1:14 pm)
@Jesse: The idea is to place the framework for your entire map into one file, so that everything is lined up in advance. You copy that master template for each component of your finished map, and delete the unnecessary parts, leaving the remainder where it is (off-center, in most cases).

Then each component will have its origin at 0,0,0, and everything lines up precisely when you import them all.

The downfall of this method appears when you have to move a connecting hall or doorway, however. Then you've either got to tweak everything attached to it, or rebuild your master template. For that reason, I like to build everything in the master template first, then break it down into components. (The master template can become a massive file if you've got a large, detailed map, so it may make sense to break your master template itself into smaller sections, splitting it up in convenient locations.)

@Cliff: I like Section 5 too, but for some reason, it renders verrrry slooooowly. =)
#14
07/06/2006 (3:50 pm)
Ahh, I see John, the problem is, in my situation at least, that the end result of what I am doing is a random layout. I understand what you mean now however with the offsets. Thanks to everyone who gave suggestions!
#15
07/06/2006 (10:19 pm)
What about constructing the map file in code and then running the map2dif program to make custom structures at runtime? Then you would have full control of the structures produced.