Tile Map Layer Collision Setup

Godot Version

4.4

Question

I am having trouble figuring out how to setup a collision box for a tilemap layer and i can’t find anything about it anywhere i have read the docs and i can’t find anything so if anyone knows how to set this up please let me know.

Everything is explained in the documentation

1 Like

the docs arent helping

What specifically is causing you trouble? Setting up collisions for different Tiles? The collision interaction with entities?

all i need is to add a collision to a tilemaplayer and i have no clue how and i cant figure it out with the docs i also suck at game dev so please explain like ur explaining to a 4 yr old lol

I’m not on my computer so tell this by memory :

  • Create a tile map layer,
  • Add a tileset in the inspector
  • Click the created tileset to expander it’s menu
  • Unfold physics part
  • Add a physics layer
  • Select the tileset panel at the bottom of the screen
  • Select the tileset you want
  • Go to paint mode using upper button
  • Select you physics layer in the list
  • Draw your collision shape to the tileset by clicking on it in the preview.

ok so i didnt work i just drew on top of it and its probably cuz my brain dont work so here are somescreenshots one is a test launch and one is the editor


The collisionshapes are there, so whats the problem?

the collision shapes dont work instead they are just blue boxes in the gameplay. and also does the hierarchy matter as far as collisions go?

hierachy doesnt really matter. you need to set up the collision layer and mask of your physics objects

heres a screenshot of what i have please let me know if i did it wrong

And what collisionmask do you have for your player?

default and i just realized that the way i am moving my character probably has something to do with this issue so i am currently using lerp whenever the right mouse button is pressed so maybe that is overriding the collision?

ok so i ran some tests and it is definitely because i am lerping the player to the mouse whenever the mouse is clicked i just tested with some rigid bodies and they are stopped by the fence so does anyone know how to workaround this

you need to set the velocity of your characterbody2d and then call “move_and_slide()” or “move_and_collide()” in the physics_process-method

ok so two questions how would i set the velocity and whats the difference between move_and_slide() and move_and_collide()
and also could i put it in a proccess funtion instead of the physics proccess function or are they different

they are different, the physics-process method gets called every physics-frame and is therefore meant to be used for moving physics-objects to ensure correct physics-behaviour. the difference between move_and_slide and move_and_collide can be found in the docs: “They are mainly used to provide high-level API to move objects with wall and slope detection (move_and_slide() method) in addition to the general collision detection provided by PhysicsBody2D.move_and_collide().”

Every characterbody has the velocity-variable:

func _physics_process(delta):
    velocity = 100 # set the velocity here
    move_and_slide()

ok thank you my brain tried to do this and i thought you had to get the velocity and then set the velocity to that so now i have a buggy version but i will swap to this thank you and im sorry if i made you explain simple things to me as my brain doesn’t like to work most days

1 Like