- Home /
How to implement "Homeworld style" movement orders with Unity?
I'm attempting to implement a system in a space RTS game where the player can order units to a three dimensional location with the mouse. They select the plane coodrdinates by clicking and holding, then press shift to select the elevation. I have included an image that demonstrates this system in Homeworld.
I know how to use the mouse for movement orders on a 2D plane, but how do I add the ability to select elevation?
Additional info: I'm using C#. The game utilizes a player controlled free camera.
Answer by mattyman174 · Jan 13, 2015 at 08:24 AM
The image you linked gives you a perfect description of what you need to do.
Check if the player is holding shift, if they are capture the current mouse position, increase or decrease the next move orders height location based upon the distance the user moves the mouse away from the origin.
When the move order is given, the distance away from the origin the mouse moved is your height elevation for that move order. A lower value from the origin will mean a decrease in height elevation and an increase from the origin will mean an increase in height elevation for that move order.
Does this answer your question?
Thanks for responding. And... Sort of. I understand the concept behind it, just having trouble figuring out how to implement it in a script.
Capture the location of the mouse on shift + mouseDown, store the x,y coords as values, and render a moveTo overlay graphic.
Then capture the distance the mouse moves AFTER shift+mouseDown to update the moveTo overlay graphics to depict the elevation change and to capture the z coord.
On mouseUp send the x,y,z values to the selected game object, trigger it's pathing script, stop rendering the moveTo overlay graphics.
I wonder if graphics for movement like the ones depicted above couldn't be done on the UI canvas now... That'd be nice.
Your answer
Follow this Question
Related Questions
Input System Can't Catch Event on Update 0 Answers
How to Move a Cube 3 Answers
Moving a gameobject with mouse 1 Answer
GetKey equivalent for mouse movement 1 Answer