Use Screencoordinates for Hit detection of player sword, dont use Map coordinates.
Because if enemy moves fast, the mapcoordinate will change before the event starts moving to the next tile.
that can cause a swordslash visibly to hit enemy, but the mechanic isnt counting it as one. this creates frustrating moments.
Screencoordinates solve this fully.
This isnt very good and just the Basics, but maybe it helps. To create a Hitbox.
Sadly i have no working Demo at the moment, only all the code scattered around.
Thanks to Caethyril for Help with the Hit Box.
Spoiler: Early ABS Swordslash
Common Event 1:
Is button W pressed? If yes activate Switch for Common Event 2.
Common Event 2:
Code:
◆Control Variables:#0004 Sword Damage = Random 1..150 //Random Damage
◆Control Variables:#0001 Sword Slash X = 0
◆Control Variables:#0002 Sword Slash Y = 0
◆If:Player is facing Down
◆Show Animation:Player, <3> Slash Down
◆Control Variables:#0002 Sword Slash Y = 48
◆
:End
◆If:Player is facing Left
◆Show Animation:Player, <3> Slash Left
◆Control Variables:#0001 Sword Slash X = -48
◆
:End
◆If:Player is facing Right
◆Show Animation:Player, <3> Slash Right
◆Control Variables:#0001 Sword Slash X = 48
◆
:End
◆If:Player is facing Up
◆Show Animation:Player, <3> Slash Up
◆Control Variables:#0002 Sword Slash Y = -48
◆
:End
◆Script:var hitDist = 0; // just for readability
: :for (var a = 3; a <= 100; a++) { // Events 3 to 100 can be Hit by Sword
: : if (!!$gameMap.event(a)) { // check that event exists
: : hitDist = Math.hypot($gameMap.event(a).screenX() - ($gamePlayer.screenX() + $gameVariables.value(1)) ,
: : $gameMap.event(a).screenY() - ($gamePlayer.screenY() + $gameVariables.value(2)) );
: : if (hitDist <= 30) { // in range?
: :
: : $gameSelfSwitches.setValue([$gameMap.mapId(), a, 'A'], true) //Hit Event got self switch A on when hit, so you can do some magic or prevent it from attacking
: : this.setSelfVariableValue($gameMap.mapId(), a, 46,this.getSelfVariableValue($gameMap.mapId(), a, 46) + $gameVariables.value(4)) // boom damage dealt, include a Death Eventpage with var46 as pagecondition and the Max HP until dead, self var plugin is awesome for this.
: : } } }
◆Loop
◆If:Button [Pagedown] is pressed down // You pressed the slash, now release it to end the event in case you kept holding that button
◆Wait:1 frame
◆
:Else
◆Break Loop
◆
:End
◆
:Repeat Above
◆Wait:2 frames
◆Control Switches:#0002 CE_Sword_Slash = OFF
I included Yanflys Self Variables Script. I made Game Variable 46 pointer to Event Self Variable. Self HP = Var46.