Where We Left Off
Iâm developing a game independently, and the game Iâve built with Bakin is also published on Freem. Iâd love for you to play it, but you can get a good idea of what the game is like from this video:
In the previous article (linked below) we implemented the enemy character (monster), including its attack motion.
In this article, Iâll implement damage processing for the playerâs sword attack hitting the enemy, and for the player receiving damage from enemy attacks.
Implementing Damage Processing for the Playerâs Attack in Bakin
Letâs add event processing to âGoblin Aââcreated in the previous articleâso it responds when hit by the playerâs attack.
Open the âCast Event Settingsâ for âGoblin Aâ in âDatabaseâ â âCastâ to bring up the âCast Eventâ screen.

Once the âCast Eventâ is open, click the second button from the left in the âSheet Listââthe âď˝ďźâ buttonâto create a new parallel event sheet.
Note: if you use the âďźâ button instead, attack processing and damage processing cannot run in parallel, so be sure to use the âď˝ďźâ button.
Once created, a new sheet starting with âP:â will appear in the âSheet List.â Name the two sheets âMovement & Attack Processingâ and âDamage Processingâ respectively.

The newly created âDamage Processingâ sheet is configured as shown below. You could keep it simpleâjust reducing the eventâs HP on contact with the playerâs âMelee Attack Actionâ castâand damage processing would still work.
However, that bare-bones approach has no atmosphere for an action game. You need to add sounds, effects, and a hit-stagger motion when the attack connects, just as shown in this sheet.


The basic flow of the damage processing is: first check whether the event made contact with the playerâs attack hitbox (implemented two articles ago).
To check contact between the playerâs attack hitbox and this event, set up a condition that detects when âthis eventâ and the âMelee Attack Actionâ cast are in contact, with âIgnore events in the process of disappearingâ checked.

When contact with the playerâs attack is detected, the first thing to do is set âStagger Flagâ to 1 (a switch would work just as well). âStagger Flagâ is a local variable I created myself.
In Bakin you can create your own variables like this for various reusable purposes (add them in the local tab of the variable settings).
âStagger Flagâ is set to 1 when the enemy character enters a staggered state after being hit, and reset to 0 when the stagger ends.
This flag is used in the other sheet, so for now just remember: create the flag, set it to 1 when hit, and reset it to 0 at the end of the hit-processing sequence.

The other elementsâwaiting for a set time, sounds, and effectsâare added to give the game atmosphere, just as in previous actions.
In the latter part of the flow the eventâs HP is reduced by 10 pointsâthatâs the actual damage the enemy character takes.
Here Iâm using a fixed 10-point reduction, but you could use variables to reduce by the playerâs attack power, or calculate the reduction after factoring in the enemyâs defense.
Next, the âMovement & Attack Processingâ event sheet content was updated from the previous article as shown below.

In short, I added a check of the âStagger Flagâ value at key points in the flow, so each part of the processing only proceeds when the flag is 0âmeaning the enemy is not in a staggered state.
Without this check, youâll find that the player attacks, the goblin is in a stagger, and yet the goblin suddenly attacks backâwhich is clearly wrong.
This happens because the two event sheetsââMovement & Attack Processingâ and âDamage Processingâârun in parallel, so even while damage is being processed on one sheet, the movement and attack logic keeps running in the background.
To prevent this, give both sheets a shared variable. While one sheet is running its logic, set the flag; clear it when done. Thatâs the fix.
There are other implementation approaches, but I believe this is the simplest solution.
Some people (especially those from a programming background) might think that checking âStagger Flagâ once at the top of âMovement & Attack Processingâ is enough to eliminate further checks. However, because the event sheets run in parallel, a single check at the top cannot handle cases where damage is received after movement has started, or where damage is received mid-attack motion.
For example, if you only check at the top, youâll see the strange behavior of the attack motion being interrupted by damage, yet the enemy suddenly attacking anyway.
Intentionally building that âhyper armorâ spec into tough enemies is fine, but if every generic enemy has it too, players wonât enjoy the game.
With all this âCast Scriptâ logic in place, you can now replicate the classic action-game behavior where Goblin A takes damage from the playerâs attack and staggers.

Implementing Damage Processing for Enemy Attacks in Bakin
Next, letâs implement damage processing for when the player takes a hit from an enemy attack.
You might think you could add the same logic to the playerâs âheroâ cast event, just as you did for âGoblin A.â But for some reason the player cast event doesnât work properly.
This is likely because Bakin treats âPlayerâ differently from regular âEventsâ internally, and setting cast events on the player cast doesnât behave well.
For that reason, player damage processing is set up in a âCommon Event.â
From Bakinâs master menu, click âCommon Event,â create a folder called âPlayer Damage Detectionâ under âCommon Events,â and inside it create an event called âGoblin Attack.â Here is what I created:

The flow is essentially the same as when Goblin A receives the playerâs attackâdamage is determined by whether the âGoblin Attackâ cast makes contact with the player.
One small difference is a local variable called âP Damageâ with a fixed value of 10.
The target whose HP is reduced is specified as âParty Member 1,â which takes advantage of the fact that the default player is always the first party member.
Since most action games are single-player, this should work without issues.
Unlike events, thereâs apparently no built-in feature to display on-screen how much HP the player lost, so you have to display the received damage as text on-screen yourself (otherwise the player has no idea how much damage they took).
To do this, I use a script that âdisplays text on-screen as an imageâ with the âP Damageâ local variable, assigning it image management number 100.
Rather than adding a damage stagger motion to the player like the enemy, which would disrupt player control whenever an enemy hits, I instead shake the screen and grant invincibility frames. Finally, the damage text image is removed. When clearing the image, you specify the management number, so I specify image number 100 (the one assigned earlier). With player-side damage processing done, go ahead and test-play.

Youâll likely notice that the goblinâs attack sometimes hits and sometimes doesnât.
The cause is that âGoblin Attackâ moves too fast: it gets pushed backward by inertia when it hits the player, and then disappears because the castâs disappear condition was triggered by colliding with the playerâall before the damage detection logic runs.
This is a tricky problem. One way to mitigate it is to prevent âGoblin Attackâ from disappearing on collision with an ally cast.

Another issue is that the default ground inertia is clearly too strong. You can reduce it by lowering the âGround Dampingâ value in the âGame Definitionâ inertia settings from the default 0.8.

Adjusting these two settings should make damage register reliably in most cases.
Youâll also likely encounter the issue where the playerâs attack motion gets canceled the instant it hits an enemy. The cause is the same: the cast disappears the moment it hits the enemy, so the rest of the cast event doesnât execute.
Try fixing this yourselfâitâs a great challenge. The fix involves either adjusting the disappear condition, or splitting the current cast into two separate ones: one for the motion and one for the hitbox.
Thereâs also the issue of the enemy suddenly vanishing when it takes the final blow, without any death animation. Itâs not technically a bug, but it feels jarring to players.
Going forward, issues like these (latent bugs) will come up frequently in game development. The approach is to investigate each one, form a hypothesis, apply a fix, and verify the result.
Whether you can take that kind of systematic approach is the clearest indicator of whether someone has an aptitude for game development and programming. If youâre serious about making games, I encourage you to embrace these challenges.
Summary
In this article I explained how to implement damage processing for both the player and enemy characters in Bakin. Combined with the previous articles, placing multiple goblins on a map should now give you a game that functions at a minimum level as an action game.
Of course, a game in this state would attract almost no players, so youâll need to add more actions, game settings, and a variety of enemies. Iâll continue covering those additions in future articlesâcheck back if youâre interested.
đ Series: RPG Maker Bakin: Game Development Guide (6/17)