Discord
Login
Community
DARK THEME

Tilemap Collision Again!!!

For my game, I really need solid collision detection for trees, buildings, etc., but I don't know how to do it. Any suggestions? Thanks.

for collision with maps, I usually use the collisions lib for the mapHit() function. something like this:

update = function()
  if keyboard.D then
    if mapHit(player.x+player.width/2+player.speed,player.y,mapName) != spriteName then
      //movement stuff
    end
  end
end

I can use it to check ahead of the object moving to see that if it isn't a specific sprite, it'll move forward. if you need to keep track of multiple wall sprites with different names then you can adjust the function like so when using a folder:

mapHit(player.x+player.width/2+player.speed,player.y,mapName).split("\")[0] != folderName then
  //movement stuff
end

if you're using a sprite sheet instead of a folder then just replace the backslash for ":"

side note: if you intend to use a camera that uses screen.setScale() then make sure to adjust for the scale in the x and y; mapHit((player.x+player.width/2+player.speed)camera.scale,player.ycamera.scale,mapName)

(side side note: this might still not work properly, adjust as needed)

So I have to use MaphIt, I'll try it but here is my actuel project:https://microstudio.io/i/Rylotox/effondrement/

I just want I just want to make the Sprite tree solid

this is if you want to put the tree sprite on a map, if you make it an object then you can use standard AABB collision but you'd have to place every tree every time you load the overworld

that's to say

Post a reply

Progress

Status

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