Doesn't fx:translate work?
Here's an adapted version of the fx animation function from exsp which simulates ProjectileSpell effects. It normally relies on spell info stored by exsp:defineSpell functions, and self is the spell object. You can however use it by passing the function a table that has the following values defined (random values below):
Code: Select all
spellData = {
_particleSystem = "fireball",
_projectileSpeed = 7.5,
_lightColor = {1.0, 1.0, 4.0},
_lightBrightness = 15,
_lightRange = 7,
_castShadow = true,
_vOffset = 1.35,
}
projectileAnimator script entity below. It sends the fx object flying from level,x, y towards facing, for a distance tiles, and if destroyFx is true, it destroys it after the distance.
Code: Select all
function animateFxObject(self, level, x, y, facing, distance, destroyFx)
-- Set particle system FX
local fxId = projectileAnimator.randomId("launchAnimationFx")
local vOffset = self._vOffset or 1.35
spawn("fx", level, x, y, facing, fxId):setParticleSystem(self._particleSystem)
local red, green, blue = unpack(self._lightColor)
local time = 10000
findEntity(fxId):setLight(red, green, blue, self._lightBrightness, self._lightRange, time, self._castShadow)
findEntity(fxId):translate(0,vOffset,0)
-- Animate FX with timer
local dx, dy = getForward(facing)
local interval = self._projectileSpeed/20
dx = dx * interval
dy = dy * interval
local fxTimer = timers:create(projectileAnimator.randomTimerId("fxTimer"))
fxTimer:setTimerInterval(0.05)
fxTimer:addCallback(
function(self, fxId, dx, dy)
if findEntity(fxId) then
findEntity(fxId):translate(dx,0,-dy)
end
end,
{fxId, dx, dy}
)
fxTimer:setTickLimit(math.ceil((20/(self._projectileSpeed/3))*distance),true)
fxTimer.fxId = fxId
fxTimer.destroyFx = destroyFx
fxTimer.onDeactivate = function(self)
if self.destroyFx then
projectileAnimator.delay(0.2,
function(self, fxId)
if findEntity(fxId) then
findEntity(fxId):destroy()
end
end,
{self.fxId}
)
end
end
fxTimer:activate()
return fxId
end
function delay(delay, funct, args)
local delayId = projectileAnimator.randomTimerId("delay")
local delayTimer = timers:create(delayId)
delayTimer:setTimerInterval(delay)
delayTimer:addCallback(funct,args)
delayTimer:setTickLimit(1,true)
delayTimer:activate()
return delayId
end
function randomId(prefix)
local numId = math.random(10000,99999)
while findEntity(prefix.."."..numId) do
numId = math.random(10000,99999)
end
return prefix.."."..numId
end
function randomTimerId(prefix)
local numId = math.random(10000,99999)
while timers:find(prefix.."."..numId) do
numId = math.random(10000,99999)
end
return prefix.."."..numId
end
EDIT: If you just want a moving light (no visuals), remove the setParticleSystem bit of code from the function where it spawns the fx.
EDIT2: You can adapt this to create effects of spells flying vertically, diagonally...
EDIT3: Framework required obviously, for timers.