Help getting mouse to interact both with game world and hud

I’m working on a game which has a top-down camera which moves around a map. Right now, the cursor is not the mouse, but is controlled by the mouse axes. The cursor itself is actually a GameObject which floats above the ground. I’m at the point where I’d like to start building a 2D HUD which does not move relative to the camera, and I’m trying to think of the best way to get the cursor seamlessly interacting both with the game world and the HUD. Like, say, Command Conquer.

At the moment I’m leaning towards the HUD being an actual 3D object as a child of the camera. That way I can cast a ray down from the cursor to determine whether mouse clicks should register in the HUD or in the game world. Is this a reasonable way to go about things? Any thoughts would be appreciated.

I realized after I switched to a 2D mouse implementation that there was a reason I had originally made it 3D: I want mouse movement to be relative to the ground, not to the camera. So my new question is what’s the easiest way to create a dynamic gui that can be used with a 3D mouse? I basically want a status display with resizable elements, some of which are buttons. I guess I’m probably looking at writing some pretty irritating code, hmm?

i don’t know command conquer so i’m not real sure what you’re after. do you mean like mouse over enlarges something and you can interact with it. then it goes back to it’s original size when the mouse exits? or do you mean something like controlling a cursor along the ground to click and position troops?

Wow, it’s pretty crazy to think that someone here doesn’t know C&C, but I suppose there are a lot 14 year olds on the forum.

C&C had two main parts to the interface: the main viewing area and a control sidebar. The sidebar included a mini-map and buttons to control what a building produced etc., similar to what you would find in a modern RTS like StarCraft, WarCraft etc.

Muriac: What are you using the 3D cursor for? How does that differ from making raycasts from a 2D cursor position (which I suspect you would need to do since a mouse can only control 2D generally). I’m really interested to hear what you’re up to!

I’m really interested in what I’m up to, too! The reason I can’t use the normal cursor and raycast from it is that I want the game cursor to move relative to the ground, not to the camera. That is, if the cursor is stationary in the game world, the camera should still be able to move. As a result, the cursor will appear to move on the screen (along with the game world) even though only the camera is moving.

I don’t want to mess around with the Mac OS cursor, since I think it will be easier to replace graphics for one I make myself. There were a few snags with getting the mouse to stay within certain boundaries and still behave normally when it got to the edges. It works really well now, though.

That is, the game world part of it works. I’m going to have to do a little WorldToViewportPoint(), GUILayer.HitTest() and ViewportPointToRay() in order to get the GUI working. But I’ll see how that goes.

someone not knowing c&c would surprise me too! i meant i don’t know its gameplay. rts isn’t my thing.

couldn’t you use guitextures for the sidebar and a second camera for the map? then use a projector in the main viewing area that shoots your cursor at the ground and is positioned to mouse x,y. you might need to tweak a positioning script if your camera isn’t straight down to account for z position. have the camera controlled by the arrow keys or something.

I think that would end up being more complicated. I’ll see how it goes my way, and report back.