How can I make my ABS (Action Battle System) allow for diagonal attacks when using a mouse click? For instance, a player enters a custom menu, equips a skill into one of five available slots, and then returns to the map. From there, they can click on the skill icon in the HUD to trigger the ability. However, when using a gamepad, the player can aim diagonally—a process handled by a “common event” that tracks movement variables. The issue is that if a player is standing still on the map and uses the skill, nothing happens because the ability relies on the player’s movement. To get around this, I initially limited the system to the four cardinal directions so that the mouse could be used directly via the HUD. That said, the gameplay feels much better with a gamepad precisely because it allows for diagonal attacks. Could I perhaps use that same movement variable to direct a mouse click? Or, alternatively, could I implement a “double-click” mechanic on the directional controller—a HUD element that acts as a virtual joystick—to allow for diagonal aiming? Essentially, the player would hold the directional input in a diagonal position and then activate the skill.
I think you could reuse that same aim variable. What if clicking the skill icon just arms the skill, and then the next click on the map sets the variable based on where you clicked compared to the player? Then it could run the skill the same way the gamepad does, and the player wouldn’t need to be moving.
For the aiming click, a parallel common event could use a Conditional Branch with the script TouchInput.isTriggered(), then a Script command like this inside it:
var dx = TouchInput.x - $gamePlayer.screenX();
var dy = TouchInput.y - ($gamePlayer.screenY() - 24);
var dirs = [6, 3, 2, 1, 4, 7, 8, 9];
var i = Math.round(Math.atan2(dy, dx) / (Math.PI / 4));
$gameVariables.setValue(10, dirs[(i + 8) % 8]);
$gameTemp.clearDestination();
Change the 10 to your aim variable. I’m guessing your variable uses numpad style numbers like Input.dir8 (8 up, 9 up right, 6 right and so on), so if yours is different you’d swap the numbers in that list. The last line stops the player from walking to where you clicked, in case the default click to move is still on. I’d also put a 1 frame Wait after arming the skill so the icon click itself doesn’t count as the aim.
The double click on the joystick could work too, but it depends on how your HUD is made. Is it a plugin, or pictures with common events?
I’m using events; the code worked perfectly, just as I had envisioned for the double-click mechanic. It creates a unique gameplay experience, since I select the ability first and then the direction via the steering-wheel-style HUD—it was just a matter of copying and pasting. Thanks!
Nice solution — arming the skill first, then using the click position to set the direction, keeps mouse aiming consistent with the gamepad controls.
Actually, it already works this way in my game, so this command isn’t being used; the issue had more to do with which switches were toggled on or off. This mode even works with a gamepad—which “charges” the ability before use—but since it relies on movement and the player was constantly moving, I hadn’t noticed the difference between using a mouse and a gamepad. It did, however, help in identifying errors within the project.