diff --git a/lib/character/behaviors/map.lua b/lib/character/behaviors/map.lua index b5c8174..d22804d 100644 --- a/lib/character/behaviors/map.lua +++ b/lib/character/behaviors/map.lua @@ -24,6 +24,17 @@ function mapBehavior.new(position, size) }, mapBehavior) end +--- @param position Vec3 +function mapBehavior:lookAt(position) + self.owner:try(Tree.behaviors.sprite, + function(sprite) + if position.x > self.displayedPosition.x then sprite.side = sprite.RIGHT end + -- (sic!) + if position.x < self.displayedPosition.x then sprite.side = sprite.LEFT end + end + ) +end + --- @param path Deque --- @param animationNode AnimationNode function mapBehavior:followPath(path, animationNode) diff --git a/lib/spellbook.lua b/lib/spellbook.lua index 0498900..7f22b1e 100644 --- a/lib/spellbook.lua +++ b/lib/spellbook.lua @@ -124,6 +124,8 @@ function attack:cast(caster, target) local targetSprite = targetCharacter:has(Tree.behaviors.sprite) if not sprite or not targetSprite then return true end + caster:try(Tree.behaviors.map, function(map) map:lookAt(target) end) + AnimationNode { onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end, children = {