Hei thanks again for the help! I feel I'm very close to the solution, however when I use your code I get the following error: "Error: game/logic/push-blocks.lua:380: attempt to call global 'canAgentMoveAndMovedBlocks' (a nil value)"darkfrei wrote: ↑Wed Feb 09, 2022 8:47 pm Here:Why you move the agent without any checking?Code: Select all
-- this is the new code in which players move inside the grid, I am trying to insert the collisions above in this new code: if moves =="right" then self.agent.tx = self.agent.tx + dt*self.agent.vx
Maybe the better solution:Code: Select all
local dx, dy = 0, 0 if move = "right" then dx = dt*self.agent.vx -- horizontal speed elseif move = "left" then dx = -dt*self.agent.vx -- minus horizontal speed if move = "down" then dy = dt*self.agent.vy -- some vertical speed elseif move = "up" then dy = -dt*self.agent.vy -- minus some (or another) vertical speed end local canMove, blocks = canAgentMoveAndMovedBlocks (dx, dy) -- returns boolean if agent and collinding blocks are movable and list of blocks to move if canMove then dx, dy = moveAgent(dx, dy) -- move agent and change dx, dy if you need moveBlocks(blocks, dx, dy) else -- change agent and blocks as stuck if you need end
I try to understand what all the variables means inside the code, but I'm struggling to see why that variable does get nil (no value). I think dy is related to vertical speed which in the pb.agent is written as "vup". I'm very confused sorry, I need time to understand and make this work.
moveAgent(dx,dy) does not exist in your library, should I make a new function? I don't understand