Lizard casting a spell: how to do correctly.
Posted: Sun Nov 11, 2012 5:51 am
I wanted a lizard casting a spell when attacking, in my case, the fireburst.
But I noticed when it does a turn attack it will keep casting it in front of it, and not where is actually attacking.
So I've figured out how can this be solved. It's a bit tricky, and not immediate, and someone might find it useful.
The code is:
I really think this can be applied to all monsters that do a turn attack (ogre, warden), if the name of the attack is the same.
But I noticed when it does a turn attack it will keep casting it in front of it, and not where is actually attacking.
So I've figured out how can this be solved. It's a bit tricky, and not immediate, and someone might find it useful.
The code is:
Code: Select all
onAttack = function(self, attack)
local dx, dy = getForward(self.facing)
if attack == "attack" then
spawn("fireburst", self.level, self.x+dx, self.y+dy, 0)
elseif attack == "turnAttackLeft" then
spawn("fireburst", self.level, self.x+dy, self.y-dx, 0)
elseif attack == "turnAttackRight" then
spawn("fireburst", self.level, self.x-dy, self.y+dx, 0)
end
end,