Hi, I'm a newbie playdate dev. I'm in the very, very early stages of making a game using Mark LaCroix's Noble Engine, and I'm editing the starter project the engine comes with. Currently I'm trying to add gravity and ground-checking to the project, but I'm having some weird issues. My player character seems to get shunted over to the far left of the screen, can't move to the right (as if it were blocked by an invisible wall) and then the game crashes after a few seconds. I'm sure I'm doing something wrong with my collision or gravity code, but I'm not sure what. The crashing issue, at least, seems to be related to using getTag, which I'm using to check if the colliding object is ground. Here's that section:
self.onGround = false local collisions = self:overlappingSprites() for i = 1, #collisions do if collisions.other:getTag() == 0 then self.onGround = true end end
and then gravity is currently just:
self.y_velocity += 0.5 * self.jump_speed
and movement is handled with moveWithCollisions
if self.x_velocity < 0 and self.x > (0 + select(1, self:getSize())) then self:moveWithCollisions(self.x + self.x_velocity, 0) elseif self.x_velocity > 0 and self.x < (400/SCALE - select(1, self:getSize())) then self:moveWithCollisions(self.x + self.x_velocity, 0) end if self.y_velocity < 0 and self.y > (0 + select(1, self:getSize())) then self:moveWithCollisions(0, self.y + self.y_velocity) elseif self.y_velocity > 0 and self.y < (240/SCALE - select(1, self:getSize())) then self:moveWithCollisions(0, self.y + self.y_velocity) end
Does anyone have any tips? I'm guessing there's probebly some stuff I'm handling in a wrong or at least unnecessary way.