Previous Blog Next Blog
Prev/Next Blog
by date

Dev Diary # 3 : Object Selection 90% complete

Dev Diary # 3 : Object Selection 90% complete
Name:Gareth Fouche
Date Posted:Jan 20, 2006
Rating:Not Rated
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Gareth Fouche

Blog post
Did a bit of work on the object selection code, and I'm happy to say its nearly done, despite a false start. The original direction I went in was extending the TSControl object to query objects under the cursor, but it turns out theres an easier way. Happily, most of what I need is contained in the existing guiCrossHair (which is, incidentally, often the case with TGE :D. The real trick is just to gain enough experience with the engine to know where to look for what you want.). It already does the client side ray casting and checking for objects, all that was needed was to extend it to save a pointer to the object it found, and provide some console accessor methods. Easy.

Then, to make the crosshair "context sensitive", I looked to one of the gui buttons, GuiBitmapButton I think it was. This button loads up a few different bitmaps, one for the normal state, one for when the button is depressed, etc. A little bit of copy-pasting, and my new AdvancedCrossHair does the same thing, loading in icons for when the thing you're looking at is something you can interact with, something to attack, something to talk to. It has a "mode" variable, and script functions to set which mode its in. There is also a script callback which determines the appropriate mode. Ie, the crosshair does the following, in this order :

1 ) clears the current object pointer.
2 ) casts its ray, setting the object pointer to whatever it finds, if it does actually find something.
3 ) Call the "SetMode" script callback
4 ) The script code sets the crosshair's state based on what the object is.
5 ) The crosshair renders with the bitmap appropriate to the state.


I left the "SetMode" logic in script for flexability, so that its easy to change later without recompiling. For instance, right now if the object is another player it sets the mode to hostile. Later on I plan to have game factions, it will analyse your standing with the target creatures faction to determine whether its hostile or not. I generally like to put these "game logic" type snippets in script, as its the kind of thing thats most likely to change over development, as you play around with different options.


Kork is the enemy, he must die!



At the moment, all static/non-static shapes show up as interactable. Hmmm, maybe I should make a "Hippy" class for my RPG, one whos main goal is to hug every tree in the game? ;)


Then it was just a matter of binding a key to a server command, one which pulls the selected object out of the crosshair, gets its ghost ID, and sends over the "Interact" command with said ID. Remember, every object the client sees is a ghost (a copy) of the original one on the server, even if Torque is running only on one machine. When the command gets to the server, it calls a function to translate this ghost ID to one of its objects IDs, then calls the servers OnInteract with it. Easy!

At the moment, all my interact script does is check if its another player, and if it is do 200 damage to it, what I like to call the Death Stare, hehe. My plan is for shapebase objects to have an OnInteract script function call which you just override for specific objects to get the desired behavior (attacking an enemy, initiating dialogue with an NPC, flipping a switch etc).


Kork recieves the Death Stare!

All in all, I'm quite happy with it, and its kinda fun making cheesy little programmer art icons. It'll have to wait a few days to get completed though, as I'm going away for the weekend. I'm definately going to enjoy my holiday....but.... once I get so close to finishing something its like an urge I gotta scratch. Part of me doesn't want to go till its done.


On a completely unrelated note, while I'm in the picture posting mood, heres a shot of a castle gate I worked on while learning Quark (remember I talked about the art "fluff" I did?), and Kork standing outside a wall/gateway I made. There was going to be a manor house in there, before I snapped out of "stuffing around with quark" mode and got back to coding.




And since I'm in the picture mood, I may as well throw in this concept art sketch I did of a generic dark knight looking fellow. Not really sure if he'll be in the game though. ;)


Recent Blog Posts
List:08/19/08 - Korrinport Reloaded
07/18/08 - SoW - More concept art
07/09/08 - It may not be Oblivion...
06/24/08 - Celebratory
05/13/08 - The Gingerbread Villa
04/14/08 - SoW - Some concept art
04/02/08 - Blog of War
02/28/08 - Scars of Bloom

Submit ResourceSubmit your own resources!

Stefan Beffy Moises   (Jan 20, 2006 at 14:54 GMT)
There was an "object selection" resource, but thats at least two years old... did you check that one out?

Toby W. Allen   (Jan 20, 2006 at 15:14 GMT)
Could you take the mission editor's selection method and tweak it to your desired effects?

Stefan Beffy Moises   (Jan 20, 2006 at 15:17 GMT)
There you go, praise the new GG search :)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2173

Mike Fosker   (Jan 20, 2006 at 15:57 GMT)
This link points to a more recent version of that resource.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7335
I've managed to get this working OK, by following his instructions, and reading the comments to make addtional changes to work in 1.4

I've not yet extended it to allow selecting of all object types, only the player and the health kits, but there are comments that cover that as well, which I have not had time to implement.
Edited on Jan 20, 2006 15:58 GMT

Jonathon Stevens   (Jan 23, 2006 at 02:52 GMT)
is this resource building Dave Myers built that Michael has linked to? If not, what will be different between the two? I'm thinking of it more for player targeting than anything else!

Gareth Fouche   (Jan 23, 2006 at 06:50 GMT)
Hehe, thanks for the links guys, but like I said in my previous .plan, I had already implemented Dave Myers Object Selection resource, and got it working fine. Its a good resource. It just didn't do exactly what I wanted. The crosshair code does.

The main difference is that the object selection (and mission editor) code is doing its ray-firing/selection only when you click the mouse, and in script, whereas the crosshair does it every frame in code. Since its happening every frame I prefer it to be in program code instead of script, its faster. The actual piece of code looks pretty similar though.

The guiCrossHairHud does almost exactly what I want. Its a gui object which, during its rendering, fires a ray into the world (on the client side), and does stuff (draws a health bar) based on the object it hits. All that was needed was to save a pointer to the found object, and to add in a few accesor methods. That took all of 10 minutes to do. The code to make the cursor change appropriately took slightly longer, about 20 minutes, including the drawing of the little icons ;).

Northeastern University (#0001)   (Feb 15, 2006 at 17:49 GMT)
I hope there's a tutorial for this.

Jonathon Stevens   (Feb 15, 2006 at 21:54 GMT)
how's the progress of this thing coming along? Still 90% finished? ;)

Gareth Fouche   (Feb 16, 2006 at 06:46 GMT)
Hehe, yes, its still 90% complete, it'll remain that way until I get a usable action for all different items in the game. The interaction system works, its complete, the missing 10% is defining onInteract() functions for all the different objects, and quite frankly it would depend on your game.

As to the tutorial, I submitted this context sensative mouse code as a tutorial on the 3rd of December, I don't know why GG hasn't approved it yet, I've got no mail saying it was denied or anything. *shrug*. I'll send them an email asking whats up, maybe they are just really busy.

Its really easy to implement though, if you dont want to wait for the tut though, just take a look at the guiShapeNameHud and the guiBitmapButton code in the engine, it just combines the two.

You must be a member and be logged in to either append comments or rate this resource.