Platformer problems with collision and movement

,

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.

1 Like

Can you provide a gif from the simulator to show how the player behaves?

For the movement part can you provide more context (more code)?

Because I don't understand what the select() is doing.
And I'd assume you have some button input to change the velocity?

Also what are you trying to achieve with this movement-snippet?
Move on ground, jump and don't walk out of the screen?