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
RTS game help - selecting units
-
- Posts: 31
- Joined: Fri Apr 21, 2006 12:00 am
- Location: Australia
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.
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.