XaiJu
thomasmoonkang
thomasmoonkang

patreon


Weekly Update #2 - Drag and drop


https://giant.gfycat.com/EsteemedVapidCobra.webm

We want moving units around to be as simple and easy as possible using drag and drop. Using Unit's Event Pointer Handler interfaces, we have access to OnBeginDrag(), OnDrag(), and OnEndDrag() which we'll trigger on the Unit itself.


OnBeginDrag() {

disable unit's collider so that we can raycast behind it

raise sorting layer

saved tile = starting tile

}


OnDrag() {

set transform to mouse position

if hovering over an empty tile, save it

if hovering over an occupied tile, save it

if hovering over another unit, save it 

}


OnEndDrag() {

if in the sell zone, sell the unit

if saved unit, swap places with it

if no unit to swap with, use the saved tile

reenable collider

reset sorting layer
}


There's a few more rules like not allowing drags during battle, and end drags on the enemy side of the field. Also checking the unit limit while still allowing tile swaps on the battlefield.

We also check whether we are moving the ally to the Bench or to the Field


Usability:

We use boxes that cover the entire tile as the colliders that the mouse can click, a lot of users may try to click the center of the character, but that won't work with multiple units next to each other. The only unoccupied space is on the tiles themselves.

We slightly highlight the occupied tiles and when hovering over a unit. Maybe we can highlight the saved tile while dragging too. May need to check if it's valid before that.


Comments

Highlighting the tiles is a great idea! Grabbing the center of the unit is more intuitive, so you have to let the players know that that's not how it works!


More Creators