KinematicBody Colliding with a wall (tilemap), how can recognize it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lucasfazzi

I have a kinematicbody2D walking randomly in 4 directions (up, right, down, left) and I want that when the kinematicbody2d collides with a wall - that is made by tilemap - it can recognize the collision, to change the direction of random move.

I was think the **is_on_wall** method was used to do this, but I didn’t understand the documentation. Am I right and **is_on_wall** will serves to me or it have another way to do the collision recognition between kinematicbody2d with a wall?

:bust_in_silhouette: Reply From: Alex Pires

In templates, take a look at “2D Platformer demo” and open the enemy.tscn. The enemy uses 4 Raycast2D do detect walls and floor, making a movent back and forth over a platform without fall:

if not detect_floor_left.is_colliding() or detect_wall_left.is_colliding():
	direction = 1.0

if not detect_floor_right.is_colliding() or detect_wall_right.is_colliding():
	direction = -1.0

made with your tip and is working perfectly.


lucasfazzi | 2019-02-25 18:25