I know some of you would kill me or themselves, when I will announce I still can’t drop any demo But I have to admit it
tl;dr: I had many troubles with creating a correct mob’s AI, but hey, there is a juicy battle right around the corner’.
I tried many times and there where many iterations and refactors. What I would like to share with you is to remember about the scope of variables! Imagine that I wasted an enormous amount of time on finding out what’s wrong, while I was overwriting the id I made local in the script of one GO and I had multiple instances of this GO in the level. Why? I didn’t realise that, when I write
local id = nil
id = go.get_id()
I actually overwrite the id that is local for all instances of this script in any new instance’s init! I know it looks stupid now and I should use
self.id, but just for my convenience I used
id because it was way easier to just use it in any function of the script not caring about passing self.id anywhere. Debugging it took a lot of time and I couldn’t find the cause of my problems because I was suspecting anything, but not this. I just, I had to complain. It might be useful information for someone someday
So, forgive me once again, guys Raising newborn twins, working full time in ICT, dog walking and caring about a new home with my wife is so time and brain consuming, that I’m only able to code in very short periods, often during communication That’s why I make small iterations and trying to keep code as clear as possible, while actually still learning Lua and Defold
But to sweeten the expectancy I must share this new AI behavior with you Let’s checkout how a basic paw-armed mob tries to kill our protagonist!
Notice the new GUI, there is a health bar (red), xp bar (yellow) and inside the orb there is a choosen element - the size of the particle fx and icon depends on amount of Elemental Energy. There are control buttons also and the button below a fireball stands also for the
Focus board, when the EE is 0. When you’ll charge it again with some element it changes for a proper spell - like fireball here. I hope you’d like it and I’m hoping for feedbacks
So another useful informations for Defold users would be to describe FSM I used to control mob and collision objects of mob used to detect, if hero enters mob’s FOV or range of attack. I used
self.new_state to change only the second variable and check for an inequality between them in update function, so for every state change I can perform different tasks only at the moment of change, because I save
new_state to the
state there immediately.
In every state I enable or disable proper collision objects and listen to
Trigger messages that are sent on collision with hero once, either at enter or exit. Or to
Animation Done messages for example. Again, I perform there different tasks and state changes, so still everything is pure and readable. It is very crucial in that kind of huge project I’m working on alone, so I give special attention to refactoring and design rules.
The damage is sent to each other at the end of animation, but it will be changed when there will be animation cursor exposed, because it will, as @britzl said:
so I’m keeping your word Then I can check for a proper moment of animation to trigger attack collision
I don’t want to show anything that could discourage you and you won’t give it another chance, as we all know that the first impression is crucial As soon as I will complete at least this basic battle behavior with interactive mobs including using some magic and (most voted) buttons for spells aaand it will be tested and playable, I will post a demo As polish studios usually says, it will be released, when it’s done