Enemies get stuck after moving sometime im moving them with constant speed using linear velocity and apply force
here is my code for enemies
main movement code is in enterFrame function
Please help
-- tiled Plugin template -- Use this as a template to extend a tiled object with functionality local M = {} function M.new(instance) if not instance then error("ERROR: Expected display object") end local left=-1 local right = 0 local accleration = 2000 local dx = 0 local max=50 --stores initial values instance.isVisible = false local parent = instance.parent local x, y = instance.x, instance.y --initialize instance local sheetInfo = require("character.zombie\_male") local myImageSheet = graphics.newImageSheet( "character/zombie\_male.png", sheetInfo:getSheet() ) instance= display.newSprite(parent, myImageSheet ,sheetInfo.sequenceData) instance.x=x instance.y=y physics.addBody(instance ,{bounce=0.0,friction=1.0,density=3}) instance.isFixedRotation=true instance.xScale=-1 instance:setSequence("walk") instance:play() --camera offset stepping function within map local function enterFrame() if instance and instance.x and instance.y and not instance.isDead then local dir=left+right dx=dir\*accleration vx,vy=instance:getLinearVelocity() instance:setLinearVelocity(dir\*max,vy) instance:applyForce(dx or 0,0,instance.x,instance.y) end end function instance:collision(event) local other=event.other local phase = event.phase if phase=="began" then if other.type~="bricks" and other.type~="hero" then instance:setSequence("walk") instance:play() if right==1 then right=0 left=-1 instance.xScale=-1 else right=1 left=0 instance.xScale=1 end end elseif phase=="end" then end end --add listeners instance:addEventListener("collision") Runtime:addEventListener( "enterFrame", enterFrame ) instance.name="zombie\_male" instance.type="zombie\_male" return instance end return M