Week11_1

Selecting multiple enemies with a self-made selection box.


Continuing on from the previous week’s work, we developed our RTS games further. We set out to accomplish a system to select multiple resources/units and to move them all at once. We accomplished this reasonably simplistically, selecting all units in a rectangular area between the two vectors of the mouse selection area.

We then created a boolean to detect if we can place buildings, the rules being if there is a building (obstacle) already underneath where we want to place the new building, or there was a unit underneath, then the canBuild bool was false.

Week11_3

When hovering a preBuilding on top of a zone where you can not place a building results in red.

 

If these things weren’t present, the bool was true and we could proceed to place the building.

Week11_2

When hovering a preBuilding on top of a zone where you can place a building results in green.

 

I didn’t take my own advice from last week, to tag the obstacle as an ‘Obstacle’, the result being that when placing a building, the y axis would increase when hovering over the obstacle, and could still be placed onto a building that had previously been placed, as it was mistakenly still tagged as ‘ground’.

On top of the placing feature, we created our own basic animation for when we do place the building. We could have chosen anything to do with the position, rotation, colour, etc. to modify for the animation. Most chose to create an animation that showed the building rising from the ground, including me.

Since this game brief ties into the assessment well, I implemented a few features outside of class to work with the assessment. I created a limit on where the camera moves based on the camera’s orthographicPosition. This worked very well as other methods I tried were either unsuccessful or gave weird results. This one also worked with the zooming capability of the camera.

Animation2

This is what is visible when the camera is fully zoomed in and pushed to the top limit.

 

For my assignment, I needed some sort of a grid system to place buildings only in certain areas, but instead of a grid system, I came up with an even better idea. Since I had planned to do a grid system, all blocks were 1×1 so that I had a base for when I was to do the grid. The block prefab that I named “Placement Cube” was modified to have a plane on top of it that acted as a 1x0x1 grid object. When you mouseOver’d onto one of these planes, the preBuilding was set to the position of the collider’s gameObject of whatever the RayHit hit from the mousePosition.

The problem with this method was that the preBuilding would be placed centre to where the mouse first entered the plane, not the centre location of the plane. Also if multiple placement cubes were next to each other, the position wouldn’t change cubes when I hovered over the next cube. So I came up with another ingenious idea, to put an empty gameObject onto the plane on the Placement Cube, and set the preBuilding to now the RayHit’s

                        collider.transform.GetChild(0).position.
                           ^                 ^
                           |                 |
                        The Plane    The Empty gameObject

This worked perfectly, and it now changes the cube it is on when I enter a new placement cube when they are next to each other. The end result:

Animation

Demonstrating the placement of a building.

 


This is Daniel Jochem, signing out.

Advertisements