Page 1 of 1

RTS game help - selecting units

Posted: Sat Aug 12, 2006 11:53 pm
by esaptonor
I have looked around and i am not sure how i am ment to do this.

i think i should have a unit class, and it looks after all data etc including its Scene node, but how should i 'select' it?
I so far think i should be getting the scene node with getSceneNodeFromScreenCoordinatesBB method, but how do i get the unit class from that so i can make its selected variable true?

i hope that was clear enough to understand,
esaptonor

Posted: Sun Aug 13, 2006 4:25 am
by Gatekeeper
I've done something similar, although it was easier for me because I only have a few selectable "things".

Give each unit a unique ID. When you make a scene node, pass the units ID as the scene node ID.

Then when the user selects a unit, you can find out what node they are selecting (using getSceneNodeFromScreenCoordinatesBB() like you said). Get this node's ID, and then you can figure out what unit has been selected. I suggest you write a helper function like "getUnitFromNodeID()" that returns a pointer to the unit.

I guess because it's an RTS you would want to select a number of units, so you could use the same concept but put everything in linked lists or an array. I don't know how you would use getSceneNodeFromScreenCoordinatesBB to get all of the nodes over an area though.

One other thing, notice how you can apply a bitmask to the getSceneNodeFromScreenCoordinatesBB? Basically, I gave all of the nodes that can't be selected (trees, ground, cucumbers) an ID below 0xFF, and all selectable objects an ID above 0xFF, so that I could use this bitmask to just get back stuff from getSceneNodeFromScreenCoordinatesBB() that could be selected.

Hope this helps.

Posted: Sun Aug 13, 2006 4:30 am
by esaptonor
thanks, that helps heaps, i was wondering what that bitmask was for!

what do you suggest occurs with finding out if the unit is an enemy or not? would i have to go all the way from the node to the unit class and check what side its on? or could it be done with the bitmask?

Posted: Sat Aug 19, 2006 4:46 am
by esaptonor
I think i have most of it sorted out, but i have no idea how that bitmask works. If all my units have IDs between 5000 and 10000 how do i make it only able to select them?
tried various numbers, but since i dont know how it works, i dont know how to make it work.

Posted: Sat Aug 19, 2006 5:02 am
by jam
Not sure if this will help you, but it was a good thread about bitmask's.

Link