Hello I’ve been having problems with the raycast and animation working together properly. What I am trying to do is get the monster to do a path and do its proper animation in that direction and continue only checking the player direction. The raycast works perfect, and all the logical checks for direction and moving sprite is working great.
The only problem is the animation gets stuck and doesn’t play properly. I been playing with it for days and can’t seem to solve this, I know the animation will get stuck in the gameLoop, so I tried to pull it out and call a function but it seems to also call the function very fast like the gameLoop and getting stuck also. Checking that with the print statement. I am using the MTE and all its functions.
Thanks for your time.
local function monsterAggro(event) print("aggro") mte.cancelSpriteMove(game.sMob\_1,false) if (player.locX == game.sMob\_1.locX and player.locY \> game.sMob\_1.locY) then game.sMob\_1:setSequence("chickenDown") elseif (player.locX == game.sMob\_1.locX and player.locY \< game.sMob\_1.locY) then game.sMob\_1:setSequence("chickenUp") elseif (player.locX \< game.sMob\_1.locX and player.locY == game.sMob\_1.locY) then game.sMob\_1:setSequence("chickenLeft") elseif (player.locX \> game.sMob\_1.locX and player.locY == game.sMob\_1.locY) then game.sMob\_1:setSequence("chickenRight") end game.sMob\_1:play() mte.moveSpriteTo({sprite = game.sMob\_1, locX = player.locX, locY = player.locY, time = 1500, transition = linear}) game.mobState = false end local function gameLoop( event ) if game.sMob\_1 ~= nil then for a = 1, 360, 20 do local startX, startY = game.sMob\_1.x, game.sMob\_1.y local endX = game.sMob\_1.x + (game.castDistance \* math.cos(math.rad(a))) local endY = game.sMob\_1.y + (game.castDistance \* math.sin(math.rad(a))) local hits = mte.physics.rayCast(startX, startY, endX, endY, "any" ) if hits and game.maxRange == false then if ( hits[1].object == player and player.level == game.sMob\_1.level ) then if game.sMob\_1Hit == false then if game.mobState ~= true then -- tried to check certain states but can't get it to work properly --Here is where it calls the function with stuck animation --mte.moveSpriteTo({sprite = game.sMob\_1, locX = player.locX, locY = player.locY, time = 1500, transition = linear, onComplete = monsterAggro()}) game.timer\_3 = timer.performWithDelay( 1000, function() monsterAggro(); end, 2 ) end end