Discord
Login
Community
DARK THEME

Help with map collision bug

Hello, so I have been experimenting with map collisions and trying to get them done as simply as possible. I believe that I have most of the things done, but there is a thing I can't seem to solve. The stutering when the object hits the map as I reset its position.

Thanks in advance :)

The code - https://microstudio.io/i/MrBoi/dungeonexplorer/

This is the best I can do for now since I'm at work:

  Collisions = function()
    local old_right = floor((player.x-player.width/2)-1)
    local old_left  = floor((player.x+player.width/2)+1)
    
    local old_up = floor((player.y-player.height/2)-1)
    local old_bottom = floor((player.y+player.height/2)+1)
    
    
    if checkMapCollision(old_left,player.y,"map",300,200) == "tile" then
      if vx > 0 then player.vx=0 end
    elsif checkMapCollision(old_right,player.y,"map",300,200) == "tile" then
      if vx < 0 then player.vx=0 end
    end
    if checkMapCollision(player.x,old_bottom,"map",300,200) == "tile" then
      if vy > 0 then player.vy=0 end
    elsif checkMapCollision(player.x,old_up,"map",300,200) == "tile" then
      if vy < 0 then player.vy=0 end
    end
  end

Basically you need to disable velocity in direction of collision,if you are colliding on the right you need to disable vx to be over 0. Note: old_left,right,up,down is just confusing don't use it please.

Thanks! I was looking at other projects when I was doing this so the variable names are interesting:), but non the less, Thank you for your help!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community