Get the normal of a TileMap collision

Godot Version



I have an Area2D bullet that has a direction and a speed and a TileMap with a collider. When this bullet hits the side of the TileMap I want the bullet to bounce off it (change the direction).

I need to get the normal of the collision with the TileMap

Like this but I need a normal:

func _on_body_entered(body):
    direction = direction.bounce(normal)

How should I do this?

An Area2D does not detect collisions. Only detects overlaps and has no information about where the overlap happened. You’ll need to use the ``PhysicsDirectSpaceState2D to query the physics server and get more information about the overlap.

Hi! I see you marked this as resolved, but I’m trying to do something simillar (getting the angle of collision between an Area2D and a Tilemap) and I can’t figure the thing out :frowning:

If you solved this, could you help providing an example of how you did it?

Thanks a lot!

1 Like

Like this:

	var collision_object = move_and_collide(linear_velocity * delta)
	if collision_object:
		if collision_object.get_collider() is TileMap:
			linear_velocity = linear_velocity.bounce(collision_object.get_normal())

Btw my bullet is a rigidbody 2d with an initial velocity.

Hope this helps :slight_smile:
sry for the late reply.
Didn’t use the other method lol.